home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume10 / xlisp21 / part06 < prev    next >
Encoding:
Text File  |  1990-02-26  |  96.0 KB  |  3,873 lines

  1. Newsgroups: comp.sources.misc
  2. organization: Cognos Inc., Ottawa, Canada
  3. subject: v10i093: XLisP 2.1 sources 3b (2/2) / 5
  4. From: garym@cognos.UUCP (Gary Murphy)
  5. Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  6.  
  7. Posting-number: Volume 10, Issue 93
  8. Submitted-by: garym@cognos.UUCP (Gary Murphy)
  9. Archive-name: xlisp21/part06
  10.  
  11. #!/bin/sh
  12. # This is a shell archive, meaning:
  13. # 1. Remove everything above the #!/bin/sh line.
  14. # 2. Save the resulting text in a file.
  15. # 3. Execute the file with /bin/sh (not csh) to create the files:
  16. #    xlfio.c
  17. #    xlftab.c
  18. #    xlglob.c
  19. #    xlimage.c
  20. #    xlinit.c
  21. #    xlio.c
  22. #    xlisp.c
  23. #    xlisp.h
  24. #    xlisp.lnk
  25. #    xlisp.mac
  26. # This archive created: Sun Feb 18 23:37:48 1990
  27. # By:    Gary Murphy ()
  28. export PATH; PATH=/bin:$PATH
  29. echo shar: extracting "'xlfio.c'" '(9976 characters)'
  30. if test -f 'xlfio.c'
  31. then
  32.     echo shar: over-writing existing file "'xlfio.c'"
  33. fi
  34. sed 's/^X//' << \SHAR_EOF > 'xlfio.c'
  35. X/* xlfio.c - xlisp file i/o */
  36. X/*    Copyright (c) 1985, by David Michael Betz
  37. X    All Rights Reserved
  38. X    Permission is granted for unrestricted non-commercial use    */
  39. X
  40. X#include "xlisp.h"
  41. X
  42. X/* external variables */
  43. Xextern LVAL k_direction,k_input,k_output;
  44. Xextern LVAL s_stdin,s_stdout,true;
  45. Xextern unsigned char buf[];
  46. Xextern int xlfsize;
  47. X
  48. X/* external routines */
  49. Xextern FILE *osaopen();
  50. X
  51. X/* forward declarations */
  52. XFORWARD LVAL getstroutput();
  53. XFORWARD LVAL printit();
  54. XFORWARD LVAL flatsize();
  55. XFORWARD LVAL openit();
  56. X
  57. X/* xread - read an expression */
  58. XLVAL xread()
  59. X{
  60. X    LVAL fptr,eof,rflag,val;
  61. X
  62. X    /* get file pointer and eof value */
  63. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  64. X    eof = (moreargs() ? xlgetarg() : NIL);
  65. X    rflag = (moreargs() ? xlgetarg() : NIL);
  66. X    xllastarg();
  67. X
  68. X    /* read an expression */
  69. X    if (!xlread(fptr,&val,rflag != NIL))
  70. X    val = eof;
  71. X
  72. X    /* return the expression */
  73. X    return (val);
  74. X}
  75. X
  76. X/* xprint - built-in function 'print' */
  77. XLVAL xprint()
  78. X{
  79. X    return (printit(TRUE,TRUE));
  80. X}
  81. X
  82. X/* xprin1 - built-in function 'prin1' */
  83. XLVAL xprin1()
  84. X{
  85. X    return (printit(TRUE,FALSE));
  86. X}
  87. X
  88. X/* xprinc - built-in function princ */
  89. XLVAL xprinc()
  90. X{
  91. X    return (printit(FALSE,FALSE));
  92. X}
  93. X
  94. X/* xterpri - terminate the current print line */
  95. XLVAL xterpri()
  96. X{
  97. X    LVAL fptr;
  98. X
  99. X    /* get file pointer */
  100. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  101. X    xllastarg();
  102. X
  103. X    /* terminate the print line and return nil */
  104. X    xlterpri(fptr);
  105. X    return (NIL);
  106. X}
  107. X
  108. X/* printit - common print function */
  109. XLOCAL LVAL printit(pflag,tflag)
  110. X  int pflag,tflag;
  111. X{
  112. X    LVAL fptr,val;
  113. X
  114. X    /* get expression to print and file pointer */
  115. X    val = xlgetarg();
  116. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  117. X    xllastarg();
  118. X
  119. X    /* print the value */
  120. X    xlprint(fptr,val,pflag);
  121. X
  122. X    /* terminate the print line if necessary */
  123. X    if (tflag)
  124. X    xlterpri(fptr);
  125. X
  126. X    /* return the result */
  127. X    return (val);
  128. X}
  129. X
  130. X/* xflatsize - compute the size of a printed representation using prin1 */
  131. XLVAL xflatsize()
  132. X{
  133. X    return (flatsize(TRUE));
  134. X}
  135. X
  136. X/* xflatc - compute the size of a printed representation using princ */
  137. XLVAL xflatc()
  138. X{
  139. X    return (flatsize(FALSE));
  140. X}
  141. X
  142. X/* flatsize - compute the size of a printed expression */
  143. XLOCAL LVAL flatsize(pflag)
  144. X  int pflag;
  145. X{
  146. X    LVAL val;
  147. X
  148. X    /* get the expression */
  149. X    val = xlgetarg();
  150. X    xllastarg();
  151. X
  152. X    /* print the value to compute its size */
  153. X    xlfsize = 0;
  154. X    xlprint(NIL,val,pflag);
  155. X
  156. X    /* return the length of the expression */
  157. X    return (cvfixnum((FIXTYPE)xlfsize));
  158. X}
  159. X
  160. X/* xopen - open a file */
  161. XLVAL xopen()
  162. X{
  163. X    char *name,*mode;
  164. X    FILE *fp;
  165. X    LVAL dir;
  166. X
  167. X    /* get the file name and direction */
  168. X    name = (char *)getstring(xlgetfname());
  169. X    if (!xlgetkeyarg(k_direction,&dir))
  170. X    dir = k_input;
  171. X
  172. X    /* get the mode */
  173. X    if (dir == k_input)
  174. X    mode = "r";
  175. X    else if (dir == k_output)
  176. X    mode = "w";
  177. X    else
  178. X    xlerror("bad direction",dir);
  179. X
  180. X    /* try to open the file */
  181. X    return ((fp = osaopen(name,mode)) ? cvfile(fp) : NIL);
  182. X}
  183. X
  184. X/* xclose - close a file */
  185. XLVAL xclose()
  186. X{
  187. X    LVAL fptr;
  188. X
  189. X    /* get file pointer */
  190. X    fptr = xlgastream();
  191. X    xllastarg();
  192. X
  193. X    /* make sure the file exists */
  194. X    if (getfile(fptr) == NULL)
  195. X    xlfail("file not open");
  196. X
  197. X    /* close the file */
  198. X    osclose(getfile(fptr));
  199. X    setfile(fptr,NULL);
  200. X
  201. X    /* return nil */
  202. X    return (NIL);
  203. X}
  204. X
  205. X/* xrdchar - read a character from a file */
  206. XLVAL xrdchar()
  207. X{
  208. X    LVAL fptr;
  209. X    int ch;
  210. X
  211. X    /* get file pointer */
  212. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  213. X    xllastarg();
  214. X
  215. X    /* get character and check for eof */
  216. X    return ((ch = xlgetc(fptr)) == EOF ? NIL : cvchar(ch));
  217. X}
  218. X
  219. X/* xrdbyte - read a byte from a file */
  220. XLVAL xrdbyte()
  221. X{
  222. X    LVAL fptr;
  223. X    int ch;
  224. X
  225. X    /* get file pointer */
  226. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  227. X    xllastarg();
  228. X
  229. X    /* get character and check for eof */
  230. X    return ((ch = xlgetc(fptr)) == EOF ? NIL : cvfixnum((FIXTYPE)ch));
  231. X}
  232. X
  233. X/* xpkchar - peek at a character from a file */
  234. XLVAL xpkchar()
  235. X{
  236. X    LVAL flag,fptr;
  237. X    int ch;
  238. X
  239. X    /* peek flag and get file pointer */
  240. X    flag = (moreargs() ? xlgetarg() : NIL);
  241. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  242. X    xllastarg();
  243. X
  244. X    /* skip leading white space and get a character */
  245. X    if (flag)
  246. X    while ((ch = xlpeek(fptr)) != EOF && isspace(ch))
  247. X        xlgetc(fptr);
  248. X    else
  249. X    ch = xlpeek(fptr);
  250. X
  251. X    /* return the character */
  252. X    return (ch == EOF ? NIL : cvchar(ch));
  253. X}
  254. X
  255. X/* xwrchar - write a character to a file */
  256. XLVAL xwrchar()
  257. X{
  258. X    LVAL fptr,chr;
  259. X
  260. X    /* get the character and file pointer */
  261. X    chr = xlgachar();
  262. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  263. X    xllastarg();
  264. X
  265. X    /* put character to the file */
  266. X    xlputc(fptr,getchcode(chr));
  267. X
  268. X    /* return the character */
  269. X    return (chr);
  270. X}
  271. X
  272. X/* xwrbyte - write a byte to a file */
  273. XLVAL xwrbyte()
  274. X{
  275. X    LVAL fptr,chr;
  276. X
  277. X    /* get the byte and file pointer */
  278. X    chr = xlgafixnum();
  279. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdout));
  280. X    xllastarg();
  281. X
  282. X    /* put byte to the file */
  283. X    xlputc(fptr,(int)getfixnum(chr));
  284. X
  285. X    /* return the character */
  286. X    return (chr);
  287. X}
  288. X
  289. X/* xreadline - read a line from a file */
  290. XLVAL xreadline()
  291. X{
  292. X    unsigned char buf[STRMAX+1],*p,*sptr;
  293. X    LVAL fptr,str,newstr;
  294. X    int len,blen,ch;
  295. X
  296. X    /* protect some pointers */
  297. X    xlsave1(str);
  298. X
  299. X    /* get file pointer */
  300. X    fptr = (moreargs() ? xlgetfile() : getvalue(s_stdin));
  301. X    xllastarg();
  302. X
  303. X    /* get character and check for eof */
  304. X    len = blen = 0; p = buf;
  305. X    while ((ch = xlgetc(fptr)) != EOF && ch != '\n') {
  306. X
  307. X    /* check for buffer overflow */
  308. X    if (blen >= STRMAX) {
  309. X         newstr = newstring(len + STRMAX + 1);
  310. X        sptr = getstring(newstr); *sptr = '\0';
  311. X        if (str) strcat(sptr,getstring(str));
  312. X        *p = '\0'; strcat(sptr,buf);
  313. X        p = buf; blen = 0;
  314. X        len += STRMAX;
  315. X        str = newstr;
  316. X    }
  317. X
  318. X    /* store the character */
  319. X    *p++ = ch; ++blen;
  320. X    }
  321. X
  322. X    /* check for end of file */
  323. X    if (len == 0 && p == buf && ch == EOF) {
  324. X    xlpop();
  325. X    return (NIL);
  326. X    }
  327. X
  328. X    /* append the last substring */
  329. X    if (str == NIL || blen) {
  330. X    newstr = newstring(len + blen + 1);
  331. X    sptr = getstring(newstr); *sptr = '\0';
  332. X    if (str) strcat(sptr,getstring(str));
  333. X    *p = '\0'; strcat(sptr,buf);
  334. X    str = newstr;
  335. X    }
  336. X
  337. X    /* restore the stack */
  338. X    xlpop();
  339. X
  340. X    /* return the string */
  341. X    return (str);
  342. X}
  343. X
  344. X
  345. X/* xmkstrinput - make a string input stream */
  346. XLVAL xmkstrinput()
  347. X{
  348. X    int start,end,len,i;
  349. X    unsigned char *str;
  350. X    LVAL string,val;
  351. X
  352. X    /* protect the return value */
  353. X    xlsave1(val);
  354. X    
  355. X    /* get the string and length */
  356. X    string = xlgastring();
  357. X    str = getstring(string);
  358. X    len = getslength(string) - 1;
  359. X
  360. X    /* get the starting offset */
  361. X    if (moreargs()) {
  362. X    val = xlgafixnum();
  363. X    start = (int)getfixnum(val);
  364. X    }
  365. X    else start = 0;
  366. X
  367. X    /* get the ending offset */
  368. X    if (moreargs()) {
  369. X    val = xlgafixnum();
  370. X    end = (int)getfixnum(val);
  371. X    }
  372. X    else end = len;
  373. X    xllastarg();
  374. X
  375. X    /* check the bounds */
  376. X    if (start < 0 || start > len)
  377. X    xlerror("string index out of bounds",cvfixnum((FIXTYPE)start));
  378. X    if (end < 0 || end > len)
  379. X    xlerror("string index out of bounds",cvfixnum((FIXTYPE)end));
  380. X
  381. X    /* make the stream */
  382. X    val = newustream();
  383. X
  384. X    /* copy the substring into the stream */
  385. X    for (i = start; i < end; ++i)
  386. X    xlputc(val,str[i]);
  387. X
  388. X    /* restore the stack */
  389. X    xlpop();
  390. X
  391. X    /* return the new stream */
  392. X    return (val);
  393. X}
  394. X
  395. X/* xmkstroutput - make a string output stream */
  396. XLVAL xmkstroutput()
  397. X{
  398. X    return (newustream());
  399. X}
  400. X
  401. X/* xgetstroutput - get output stream string */
  402. XLVAL xgetstroutput()
  403. X{
  404. X    LVAL stream;
  405. X    stream = xlgaustream();
  406. X    xllastarg();
  407. X    return (getstroutput(stream));
  408. X}
  409. X
  410. X/* xgetlstoutput - get output stream list */
  411. XLVAL xgetlstoutput()
  412. X{
  413. X    LVAL stream,val;
  414. X
  415. X    /* get the stream */
  416. X    stream = xlgaustream();
  417. X    xllastarg();
  418. X
  419. X    /* get the output character list */
  420. X    val = gethead(stream);
  421. X
  422. X    /* empty the character list */
  423. X    sethead(stream,NIL);
  424. X    settail(stream,NIL);
  425. X
  426. X    /* return the list */
  427. X    return (val);
  428. X}
  429. X
  430. X/* xformat - formatted output function */
  431. XLVAL xformat()
  432. X{
  433. X    LVAL fmtstring,stream,val;
  434. X    unsigned char *fmt;
  435. X    int ch;
  436. X
  437. X    /* protect some pointers */
  438. X    xlstkcheck(2);
  439. X    xlsave(fmtstring);
  440. X    xlsave(stream);
  441. X
  442. X    /* get the stream and format string */
  443. X    stream = xlgetarg();
  444. X    if (stream == NIL)
  445. X    val = stream = newustream();
  446. X    else {
  447. X    if (stream == true)
  448. X        stream = getvalue(s_stdout);
  449. X    else if (!streamp(stream) && !ustreamp(stream))
  450. X        xlbadtype(stream);
  451. X    val = NIL;
  452. X    }
  453. X    fmtstring = xlgastring();
  454. X    fmt = getstring(fmtstring);
  455. X
  456. X    /* process the format string */
  457. X    while (ch = *fmt++)
  458. X    if (ch == '~') {
  459. X        switch (*fmt++) {
  460. X        case '\0':
  461. X        xlerror("expecting a format directive",cvstring(fmt-1));
  462. X        case 'a': case 'A':
  463. X        xlprint(stream,xlgetarg(),FALSE);
  464. X        break;
  465. X        case 's': case 'S':
  466. X        xlprint(stream,xlgetarg(),TRUE);
  467. X        break;
  468. X        case '%':
  469. X        xlterpri(stream);
  470. X        break;
  471. X        case '~':
  472. X        xlputc(stream,'~');
  473. X        break;
  474. X        case '\n':
  475. X        while (*fmt && *fmt != '\n' && isspace(*fmt))
  476. X            ++fmt;
  477. X        break;
  478. X        default:
  479. X        xlerror("unknown format directive",cvstring(fmt-1));
  480. X        }
  481. X    }
  482. X    else
  483. X        xlputc(stream,ch);
  484. X    
  485. X    /* get the output string for a stream argument of NIL */
  486. X    if (val) val = getstroutput(val);
  487. X    xlpopn(2);
  488. X        
  489. X    /* return the value */
  490. X    return (val);
  491. X}
  492. X
  493. X/* getstroutput - get the output stream string (internal) */
  494. XLOCAL LVAL getstroutput(stream)
  495. X  LVAL stream;
  496. X{
  497. X    unsigned char *str;
  498. X    LVAL next,val;
  499. X    int len,ch;
  500. X
  501. X    /* compute the length of the stream */
  502. X    for (len = 0, next = gethead(stream); next != NIL; next = cdr(next))
  503. X    ++len;
  504. X
  505. X    /* create a new string */
  506. X    val = newstring(len + 1);
  507. X    
  508. X    /* copy the characters into the new string */
  509. X    str = getstring(val);
  510. X    while ((ch = xlgetc(stream)) != EOF)
  511. X    *str++ = ch;
  512. X    *str = '\0';
  513. X
  514. X    /* return the string */
  515. X    return (val);
  516. X}
  517. X
  518. SHAR_EOF
  519. if test 9976 -ne "`wc -c 'xlfio.c'`"
  520. then
  521.     echo shar: error transmitting "'xlfio.c'" '(should have been 9976 characters)'
  522. fi
  523. echo shar: extracting "'xlftab.c'" '(16622 characters)'
  524. if test -f 'xlftab.c'
  525. then
  526.     echo shar: over-writing existing file "'xlftab.c'"
  527. fi
  528. sed 's/^X//' << \SHAR_EOF > 'xlftab.c'
  529. X/* xlftab.c - xlisp function table */
  530. X/*    Copyright (c) 1985, by David Michael Betz
  531. X    All Rights Reserved
  532. X    Permission is granted for unrestricted non-commercial use    */
  533. X
  534. X#include "xlisp.h"
  535. X
  536. X/* external functions */
  537. Xextern LVAL
  538. X    xbisubr(),xbifsubr(),
  539. X    rmhash(),rmquote(),rmdquote(),rmbquote(),rmcomma(),
  540. X    clnew(),clisnew(),clanswer(),
  541. X    obisnew(),obclass(),obshow(),
  542. X    rmlpar(),rmrpar(),rmsemi(),
  543. X    xeval(),xapply(),xfuncall(),xquote(),xfunction(),xbquote(),
  544. X    xlambda(),xset(),xsetq(),xsetf(),xdefun(),xdefmacro(),
  545. X    xgensym(),xmakesymbol(),xintern(),
  546. X    xsymname(),xsymvalue(),xsymplist(),
  547. X    xget(),xputprop(),xremprop(),
  548. X    xhash(),xmkarray(),xaref(),
  549. X    xcar(),xcdr(),
  550. X    xcaar(),xcadr(),xcdar(),xcddr(),
  551. X    xcaaar(),xcaadr(),xcadar(),xcaddr(),
  552. X    xcdaar(),xcdadr(),xcddar(),xcdddr(),
  553. X    xcaaaar(),xcaaadr(),xcaadar(),xcaaddr(),
  554. X    xcadaar(),xcadadr(),xcaddar(),xcadddr(),
  555. X    xcdaaar(),xcdaadr(),xcdadar(),xcdaddr(),
  556. X    xcddaar(),xcddadr(),xcdddar(),xcddddr(),
  557. X    xcons(),xlist(),xappend(),xreverse(),xlast(),xnth(),xnthcdr(),
  558. X    xmember(),xassoc(),xsubst(),xsublis(),xlength(),xsort(),
  559. X    xremove(),xremif(),xremifnot(),
  560. X    xmapc(),xmapcar(),xmapl(),xmaplist(),
  561. X    xrplca(),xrplcd(),xnconc(),
  562. X    xdelete(),xdelif(),xdelifnot(),
  563. X    xatom(),xsymbolp(),xnumberp(),xboundp(),xnull(),xlistp(),xendp(),xconsp(),
  564. X    xeq(),xeql(),xequal(),
  565. X    xcond(),xcase(),xand(),xor(),xlet(),xletstar(),xif(),
  566. X    xprog(),xprogstar(),xprog1(),xprog2(),xprogn(),xgo(),xreturn(),
  567. X    xcatch(),xthrow(),
  568. X    xerror(),xcerror(),xbreak(),
  569. X    xcleanup(),xtoplevel(),xcontinue(),xerrset(),
  570. X    xbaktrace(),xevalhook(),
  571. X    xdo(),xdostar(),xdolist(),xdotimes(),
  572. X    xminusp(),xzerop(),xplusp(),xevenp(),xoddp(),
  573. X    xfix(),xfloat(),
  574. X    xgcd(),xadd(),xsub(),xmul(),xdiv(),xrem(),xmin(),xmax(),xabs(),
  575. X    xadd1(),xsub1(),xlogand(),xlogior(),xlogxor(),xlognot(),
  576. X    xsin(),xcos(),xtan(),xexpt(),xexp(),xsqrt(),xrand(),
  577. X    xlss(),xleq(),xequ(),xneq(),xgeq(),xgtr(),
  578. X    xstrcat(),xsubseq(),xstring(),xchar(),
  579. X    xread(),xprint(),xprin1(),xprinc(),xterpri(),
  580. X    xflatsize(),xflatc(),
  581. X    xopen(),xclose(),xrdchar(),xpkchar(),xwrchar(),xreadline(),
  582. X    xload(),xtranscript(),
  583. X    xtype(),xexit(),xpeek(),xpoke(),xaddrs(),
  584. X    xvector(),xblock(),xrtnfrom(),xtagbody(),
  585. X    xpsetq(),xflet(),xlabels(),xmacrolet(),xunwindprotect(),xpp(),
  586. X    xstrlss(),xstrleq(),xstreql(),xstrneq(),xstrgeq(),xstrgtr(),
  587. X    xstrilss(),xstrileq(),xstrieql(),xstrineq(),xstrigeq(),xstrigtr(),
  588. X    xupcase(),xdowncase(),xnupcase(),xndowncase(),
  589. X    xtrim(),xlefttrim(),xrighttrim(),
  590. X    xuppercasep(),xlowercasep(),xbothcasep(),xdigitp(),xalphanumericp(),
  591. X    xcharcode(),xcodechar(),xchupcase(),xchdowncase(),xdigitchar(),
  592. X    xchrlss(),xchrleq(),xchreql(),xchrneq(),xchrgeq(),xchrgtr(),
  593. X    xchrilss(),xchrileq(),xchrieql(),xchrineq(),xchrigeq(),xchrigtr(),
  594. X    xintegerp(),xfloatp(),xstringp(),xarrayp(),xstreamp(),xobjectp(),
  595. X    xwhen(),xunless(),xloop(),
  596. X    xsymfunction(),xfboundp(),xsend(),xsendsuper(),
  597. X    xprogv(),xrdbyte(),xwrbyte(),xformat(),
  598. X    xcharp(),xcharint(),xintchar(),
  599. X    xmkstrinput(),xmkstroutput(),xgetstroutput(),xgetlstoutput(),
  600. X    xgetlambda(),xmacroexpand(),x1macroexpand(),
  601. X    xtrace(),xuntrace(),
  602. X    xdefstruct(),xmkstruct(),xcpystruct(),xstrref(),xstrset(),xstrtypep(),
  603. X    xasin(),xacos(),xatan();
  604. X
  605. X/* functions specific to xldmem.c */
  606. XLVAL xgc(),xexpand(),xalloc(),xmem();
  607. X#ifdef SAVERESTORE
  608. XLVAL xsave(),xrestore();
  609. X#endif
  610. X
  611. X/* include system dependant definitions */
  612. X#include "osdefs.h"
  613. X
  614. X/* SUBR/FSUBR indicator */
  615. X#define S    SUBR
  616. X#define F    FSUBR
  617. X
  618. X/* forward declarations */
  619. XLVAL xnotimp();
  620. X
  621. X/* the function table */
  622. XFUNDEF funtab[] = {
  623. X
  624. X    /* read macro functions */
  625. X{    NULL,                S, rmhash        }, /*   0 */
  626. X{    NULL,                S, rmquote        }, /*   1 */
  627. X{    NULL,                S, rmdquote        }, /*   2 */
  628. X{    NULL,                S, rmbquote        }, /*   3 */
  629. X{    NULL,                S, rmcomma        }, /*   4 */
  630. X{    NULL,                S, rmlpar        }, /*   5 */
  631. X{    NULL,                S, rmrpar        }, /*   6 */
  632. X{    NULL,                S, rmsemi        }, /*   7 */
  633. X{    NULL,                S, xnotimp        }, /*   8 */
  634. X{    NULL,                S, xnotimp        }, /*   9 */
  635. X
  636. X    /* methods */
  637. X{    NULL,                S, clnew        }, /*  10 */
  638. X{    NULL,                S, clisnew        }, /*  11 */
  639. X{    NULL,                S, clanswer        }, /*  12 */
  640. X{    NULL,                S, obisnew        }, /*  13 */
  641. X{    NULL,                S, obclass        }, /*  14 */
  642. X{    NULL,                S, obshow        }, /*  15 */
  643. X{    NULL,                S, xnotimp        }, /*  16 */
  644. X{    NULL,                S, xnotimp        }, /*  17 */
  645. X{    NULL,                S, xnotimp        }, /*  18 */
  646. X{    NULL,                S, xnotimp        }, /*  19 */
  647. X
  648. X    /* evaluator functions */
  649. X{    "EVAL",                S, xeval        }, /*  20 */
  650. X{    "APPLY",            S, xapply        }, /*  21 */
  651. X{    "FUNCALL",            S, xfuncall        }, /*  22 */
  652. X{    "QUOTE",            F, xquote        }, /*  23 */
  653. X{    "FUNCTION",            F, xfunction        }, /*  24 */
  654. X{    "BACKQUOTE",            F, xbquote        }, /*  25 */
  655. X{    "LAMBDA",            F, xlambda        }, /*  26 */
  656. X
  657. X    /* symbol functions */
  658. X{    "SET",                S, xset            }, /*  27 */
  659. X{    "SETQ",                F, xsetq        }, /*  28 */
  660. X{    "SETF",                F, xsetf        }, /*  29 */
  661. X{    "DEFUN",            F, xdefun        }, /*  30 */
  662. X{    "DEFMACRO",            F, xdefmacro        }, /*  31 */
  663. X{    "GENSYM",            S, xgensym        }, /*  32 */
  664. X{    "MAKE-SYMBOL",            S, xmakesymbol        }, /*  33 */
  665. X{    "INTERN",             S, xintern        }, /*  34 */
  666. X{    "SYMBOL-NAME",            S, xsymname        }, /*  35 */
  667. X{    "SYMBOL-VALUE",            S, xsymvalue        }, /*  36 */
  668. X{    "SYMBOL-PLIST",            S, xsymplist        }, /*  37 */
  669. X{    "GET",                S, xget            }, /*  38 */
  670. X{    "PUTPROP",             S, xputprop        }, /*  39 */
  671. X{    "REMPROP",            S, xremprop        }, /*  40 */
  672. X{    "HASH",                S, xhash        }, /*  41 */
  673. X
  674. X    /* array functions */
  675. X{    "MAKE-ARRAY",            S, xmkarray        }, /*  42 */
  676. X{    "AREF",                S, xaref        }, /*  43 */
  677. X            
  678. X    /* list functions */
  679. X{    "CAR",                S, xcar            }, /*  44 */
  680. X{    "CDR",                S, xcdr            }, /*  45 */
  681. X            
  682. X{    "CAAR",                S, xcaar        }, /*  46 */
  683. X{    "CADR",                S, xcadr        }, /*  47 */
  684. X{    "CDAR",                S, xcdar        }, /*  48 */
  685. X{    "CDDR",                S, xcddr        }, /*  49 */
  686. X
  687. X{    "CAAAR",            S, xcaaar        }, /*  50 */
  688. X{    "CAADR",            S, xcaadr        }, /*  51 */
  689. X{    "CADAR",            S, xcadar        }, /*  52 */
  690. X{    "CADDR",            S, xcaddr        }, /*  53 */
  691. X{    "CDAAR",            S, xcdaar        }, /*  54 */
  692. X{    "CDADR",            S, xcdadr        }, /*  55 */
  693. X{    "CDDAR",            S, xcddar        }, /*  56 */
  694. X{    "CDDDR",            S, xcdddr        }, /*  57 */
  695. X
  696. X{    "CAAAAR",             S, xcaaaar        }, /*  58 */
  697. X{    "CAAADR",            S, xcaaadr        }, /*  59 */
  698. X{    "CAADAR",            S, xcaadar        }, /*  60 */
  699. X{    "CAADDR",            S, xcaaddr        }, /*  61 */
  700. X{    "CADAAR",             S, xcadaar        }, /*  62 */
  701. X{    "CADADR",            S, xcadadr        }, /*  63 */
  702. X{    "CADDAR",            S, xcaddar        }, /*  64 */
  703. X{    "CADDDR",            S, xcadddr        }, /*  65 */
  704. X{    "CDAAAR",            S, xcdaaar        }, /*  66 */
  705. X{    "CDAADR",            S, xcdaadr        }, /*  67 */
  706. X{    "CDADAR",            S, xcdadar        }, /*  68 */
  707. X{    "CDADDR",            S, xcdaddr        }, /*  69 */
  708. X{    "CDDAAR",            S, xcddaar        }, /*  70 */
  709. X{    "CDDADR",            S, xcddadr        }, /*  71 */
  710. X{    "CDDDAR",            S, xcdddar        }, /*  72 */
  711. X{    "CDDDDR",            S, xcddddr        }, /*  73 */
  712. X
  713. X{    "CONS",                S, xcons        }, /*  74 */
  714. X{    "LIST",                S, xlist        }, /*  75 */
  715. X{    "APPEND",            S, xappend        }, /*  76 */
  716. X{    "REVERSE",            S, xreverse        }, /*  77 */
  717. X{    "LAST",                S, xlast        }, /*  78 */
  718. X{    "NTH",                S, xnth            }, /*  79 */
  719. X{    "NTHCDR",            S, xnthcdr        }, /*  80 */
  720. X{    "MEMBER",            S, xmember        }, /*  81 */
  721. X{    "ASSOC",            S, xassoc        }, /*  82 */
  722. X{    "SUBST",             S, xsubst        }, /*  83 */
  723. X{    "SUBLIS",            S, xsublis        }, /*  84 */
  724. X{    "REMOVE",            S, xremove        }, /*  85 */
  725. X{    "LENGTH",            S, xlength        }, /*  86 */
  726. X{    "MAPC",                S, xmapc        }, /*  87 */
  727. X{    "MAPCAR",            S, xmapcar        }, /*  88 */
  728. X{    "MAPL",                S, xmapl        }, /*  89 */
  729. X{    "MAPLIST",            S, xmaplist        }, /*  90 */
  730. X            
  731. X    /* destructive list functions */
  732. X{    "RPLACA",            S, xrplca        }, /*  91 */
  733. X{    "RPLACD",            S, xrplcd        }, /*  92 */
  734. X{    "NCONC",            S, xnconc        }, /*  93 */
  735. X{    "DELETE",            S, xdelete        }, /*  94 */
  736. X
  737. X    /* predicate functions */
  738. X{    "ATOM",                S, xatom        }, /*  95 */
  739. X{    "SYMBOLP",            S, xsymbolp        }, /*  96 */
  740. X{    "NUMBERP",            S, xnumberp        }, /*  97 */
  741. X{    "BOUNDP",            S, xboundp         }, /*  98 */
  742. X{    "NULL",                S, xnull        }, /*  99 */
  743. X{    "LISTP",            S, xlistp        }, /* 100 */
  744. X{    "CONSP",            S, xconsp        }, /* 101 */
  745. X{    "MINUSP",            S, xminusp         }, /* 102 */
  746. X{    "ZEROP",            S, xzerop        }, /* 103 */
  747. X{    "PLUSP",            S, xplusp        }, /* 104 */
  748. X{    "EVENP",            S, xevenp        }, /* 105 */
  749. X{    "ODDP",                S, xoddp        }, /* 106 */
  750. X{    "EQ",                S, xeq            }, /* 107 */
  751. X{    "EQL",                S, xeql            }, /* 108 */
  752. X{    "EQUAL",            S, xequal        }, /* 109 */
  753. X
  754. X    /* special forms */
  755. X{    "COND",                F, xcond        }, /* 110 */
  756. X{    "CASE",                F, xcase        }, /* 111 */
  757. X{    "AND",                F, xand            }, /* 112 */
  758. X{    "OR",                F, xor            }, /* 113 */
  759. X{    "LET",                F, xlet            }, /* 114 */
  760. X{    "LET*",                F, xletstar        }, /* 115 */
  761. X{    "IF",                F, xif            }, /* 116 */
  762. X{    "PROG",                F, xprog        }, /* 117 */
  763. X{    "PROG*",            F, xprogstar        }, /* 118 */
  764. X{    "PROG1",            F, xprog1        }, /* 119 */
  765. X{    "PROG2",            F, xprog2        }, /* 120 */
  766. X{    "PROGN",            F, xprogn        }, /* 121 */
  767. X{    "GO",                F, xgo            }, /* 122 */
  768. X{    "RETURN",            F, xreturn          }, /* 123 */
  769. X{    "DO",                F, xdo            }, /* 124 */
  770. X{    "DO*",                F, xdostar          }, /* 125 */
  771. X{    "DOLIST",            F, xdolist          }, /* 126 */
  772. X{    "DOTIMES",            F, xdotimes        }, /* 127 */
  773. X{    "CATCH",            F, xcatch        }, /* 128 */
  774. X{    "THROW",            F, xthrow        }, /* 129 */
  775. X    
  776. X    /* debugging and error handling functions */
  777. X{    "ERROR",            S, xerror        }, /* 130 */
  778. X{    "CERROR",            S, xcerror          }, /* 131 */
  779. X{    "BREAK",            S, xbreak        }, /* 132 */
  780. X{    "CLEAN-UP",            S, xcleanup        }, /* 133 */
  781. X{    "TOP-LEVEL",            S, xtoplevel        }, /* 134 */
  782. X{    "CONTINUE",            S, xcontinue        }, /* 135 */
  783. X{    "ERRSET",             F, xerrset          }, /* 136 */
  784. X{    "BAKTRACE",            S, xbaktrace        }, /* 137 */
  785. X{    "EVALHOOK",            S, xevalhook        }, /* 138 */
  786. X
  787. X    /* arithmetic functions */
  788. X{    "TRUNCATE",            S, xfix            }, /* 139 */
  789. X{    "FLOAT",            S, xfloat        }, /* 140 */
  790. X{    "+",                S, xadd            }, /* 141 */
  791. X{    "-",                S, xsub            }, /* 142 */
  792. X{    "*",                S, xmul            }, /* 143 */
  793. X{    "/",                S, xdiv            }, /* 144 */
  794. X{    "1+",                S, xadd1        }, /* 145 */
  795. X{    "1-",                S, xsub1        }, /* 146 */
  796. X{    "REM",                S, xrem            }, /* 147 */
  797. X{    "MIN",                S, xmin            }, /* 148 */
  798. X{    "MAX",                S, xmax            }, /* 149 */
  799. X{    "ABS",                S, xabs            }, /* 150 */
  800. X{    "SIN",                S, xsin            }, /* 151 */
  801. X{    "COS",                S, xcos            }, /* 152 */
  802. X{    "TAN",                S, xtan            }, /* 153 */
  803. X{    "EXPT",                S, xexpt        }, /* 154 */
  804. X{    "EXP",                S, xexp            }, /* 155 */
  805. X{    "SQRT",                  S, xsqrt        }, /* 156 */
  806. X{    "RANDOM",            S, xrand        }, /* 157 */
  807. X            
  808. X    /* bitwise logical functions */
  809. X{    "LOGAND",            S, xlogand          }, /* 158 */
  810. X{    "LOGIOR",            S, xlogior          }, /* 159 */
  811. X{    "LOGXOR",            S, xlogxor          }, /* 160 */
  812. X{    "LOGNOT",            S, xlognot          }, /* 161 */
  813. X
  814. X    /* numeric comparison functions */
  815. X{    "<",                S, xlss            }, /* 162 */
  816. X{    "<=",                S, xleq            }, /* 163 */
  817. X{    "=",                S, xequ            }, /* 164 */
  818. X{    "/=",                S, xneq            }, /* 165 */
  819. X{    ">=",                S, xgeq            }, /* 166 */
  820. X{    ">",                S, xgtr            }, /* 167 */
  821. X            
  822. X    /* string functions */
  823. X{    "STRCAT",            S, xstrcat          }, /* 168 */
  824. X{    "SUBSEQ",            S, xsubseq          }, /* 169 */
  825. X{    "STRING",            S, xstring          }, /* 170 */
  826. X{    "CHAR",                S, xchar        }, /* 171 */
  827. X
  828. X    /* I/O functions */
  829. X{    "READ",                S, xread        }, /* 172 */
  830. X{    "PRINT",            S, xprint        }, /* 173 */
  831. X{    "PRIN1",            S, xprin1        }, /* 174 */
  832. X{    "PRINC",            S, xprinc        }, /* 175 */
  833. X{    "TERPRI",            S, xterpri          }, /* 176 */
  834. X{    "FLATSIZE",            S, xflatsize        }, /* 177 */
  835. X{    "FLATC",            S, xflatc        }, /* 178 */
  836. X            
  837. X    /* file I/O functions */
  838. X{    "OPEN",                S, xopen        }, /* 179 */
  839. X{    "FORMAT",            S, xformat          }, /* 180 */
  840. X{    "CLOSE",            S, xclose        }, /* 181 */
  841. X{    "READ-CHAR",            S, xrdchar          }, /* 182 */
  842. X{    "PEEK-CHAR",            S, xpkchar          }, /* 183 */
  843. X{    "WRITE-CHAR",            S, xwrchar          }, /* 184 */
  844. X{    "READ-LINE",            S, xreadline        }, /* 185 */
  845. X
  846. X    /* system functions */
  847. X{    "LOAD",                S, xload        }, /* 186 */
  848. X{    "DRIBBLE",            S, xtranscript        }, /* 187 */
  849. X
  850. X/* functions specific to xldmem.c */
  851. X{    "GC",                S, xgc            }, /* 188 */
  852. X{    "EXPAND",            S, xexpand          }, /* 189 */
  853. X{    "ALLOC",            S, xalloc        }, /* 190 */
  854. X{    "ROOM",                S, xmem            }, /* 191 */
  855. X#ifdef SAVERESTORE
  856. X{    "SAVE",                S, xsave        }, /* 192 */
  857. X{    "RESTORE",            S, xrestore        }, /* 193 */
  858. X#else
  859. X{    NULL,                S, xnotimp        }, /* 192 */
  860. X{    NULL,                S, xnotimp        }, /* 193 */
  861. X#endif
  862. X/* end of functions specific to xldmem.c */
  863. X
  864. X{    "TYPE-OF",            S, xtype        }, /* 194 */
  865. X{    "EXIT",                S, xexit        }, /* 195 */
  866. X{    "PEEK",                S, xpeek        }, /* 196 */
  867. X{    "POKE",                S, xpoke        }, /* 197 */
  868. X{    "ADDRESS-OF",            S, xaddrs        }, /* 198 */
  869. X
  870. X    /* new functions and special forms */
  871. X{    "VECTOR",            S, xvector          }, /* 199 */
  872. X{    "BLOCK",            F, xblock        }, /* 200 */
  873. X{    "RETURN-FROM",            F, xrtnfrom        }, /* 201 */
  874. X{    "TAGBODY",            F, xtagbody        }, /* 202 */
  875. X{    "PSETQ",            F, xpsetq        }, /* 203 */
  876. X{    "FLET",                F, xflet        }, /* 204 */
  877. X{    "LABELS",            F, xlabels          }, /* 205 */
  878. X{    "MACROLET",            F, xmacrolet        }, /* 206 */
  879. X{    "UNWIND-PROTECT",        F, xunwindprotect    }, /* 207 */
  880. X{    "PPRINT",            S, xpp            }, /* 208 */
  881. X{    "STRING<",            S, xstrlss          }, /* 209 */
  882. X{    "STRING<=",            S, xstrleq          }, /* 210 */
  883. X{    "STRING=",            S, xstreql          }, /* 211 */
  884. X{    "STRING/=",            S, xstrneq          }, /* 212 */
  885. X{    "STRING>=",            S, xstrgeq          }, /* 213 */
  886. X{    "STRING>",            S, xstrgtr          }, /* 214 */
  887. X{    "STRING-LESSP",            S, xstrilss        }, /* 215 */
  888. X{    "STRING-NOT-GREATERP",        S, xstrileq        }, /* 216 */
  889. X{    "STRING-EQUAL",            S, xstrieql        }, /* 217 */
  890. X{    "STRING-NOT-EQUAL",        S, xstrineq        }, /* 218 */
  891. X{    "STRING-NOT-LESSP",        S, xstrigeq        }, /* 219 */
  892. X{    "STRING-GREATERP",        S, xstrigtr        }, /* 220 */
  893. X{    "INTEGERP",            S, xintegerp        }, /* 221 */
  894. X{    "FLOATP",            S, xfloatp          }, /* 222 */
  895. X{    "STRINGP",            S, xstringp        }, /* 223 */
  896. X{    "ARRAYP",            S, xarrayp          }, /* 224 */
  897. X{    "STREAMP",            S, xstreamp        }, /* 225 */
  898. X{    "OBJECTP",            S, xobjectp        }, /* 226 */
  899. X{    "STRING-UPCASE",        S, xupcase          }, /* 227 */
  900. X{    "STRING-DOWNCASE",        S, xdowncase        }, /* 228 */
  901. X{    "NSTRING-UPCASE",        S, xnupcase        }, /* 229 */
  902. X{    "NSTRING-DOWNCASE",        S, xndowncase        }, /* 230 */
  903. X{    "STRING-TRIM",            S, xtrim        }, /* 231 */
  904. X{    "STRING-LEFT-TRIM",        S, xlefttrim        }, /* 232 */
  905. X{    "STRING-RIGHT-TRIM",        S, xrighttrim        }, /* 233 */
  906. X{    "WHEN",                F, xwhen        }, /* 234 */
  907. X{    "UNLESS",            F, xunless          }, /* 235 */
  908. X{    "LOOP",                F, xloop        }, /* 236 */
  909. X{    "SYMBOL-FUNCTION",        S, xsymfunction        }, /* 237 */
  910. X{    "FBOUNDP",            S, xfboundp        }, /* 238 */
  911. X{    "SEND",                S, xsend        }, /* 239 */
  912. X{    "SEND-SUPER",            S, xsendsuper        }, /* 240 */
  913. X{    "PROGV",            F, xprogv        }, /* 241 */
  914. X{    "CHARACTERP",            S, xcharp        }, /* 242 */
  915. X{    "CHAR-INT",            S, xcharint        }, /* 243 */
  916. X{    "INT-CHAR",            S, xintchar        }, /* 244 */
  917. X{    "READ-BYTE",            S, xrdbyte          }, /* 245 */
  918. X{    "WRITE-BYTE",            S, xwrbyte          }, /* 246 */
  919. X{    "MAKE-STRING-INPUT-STREAM",     S, xmkstrinput        }, /* 247 */
  920. X{    "MAKE-STRING-OUTPUT-STREAM",    S, xmkstroutput        }, /* 248 */
  921. X{    "GET-OUTPUT-STREAM-STRING",    S, xgetstroutput    }, /* 249 */
  922. X{    "GET-OUTPUT-STREAM-LIST",    S, xgetlstoutput    }, /* 250 */
  923. X{    "GCD",                S, xgcd            }, /* 251 */
  924. X{    "GET-LAMBDA-EXPRESSION",     S, xgetlambda        }, /* 252 */
  925. X{    "MACROEXPAND",            S, xmacroexpand        }, /* 253 */
  926. X{    "MACROEXPAND-1",        S, x1macroexpand    }, /* 254 */
  927. X{    "CHAR<",            S, xchrlss          }, /* 255 */
  928. X{    "CHAR<=",            S, xchrleq          }, /* 256 */
  929. X{    "CHAR=",            S, xchreql          }, /* 257 */
  930. X{    "CHAR/=",            S, xchrneq          }, /* 258 */
  931. X{    "CHAR>=",            S, xchrgeq          }, /* 259 */
  932. X{    "CHAR>",            S, xchrgtr          }, /* 260 */
  933. X{    "CHAR-LESSP",            S, xchrilss        }, /* 261 */
  934. X{    "CHAR-NOT-GREATERP",        S, xchrileq        }, /* 262 */
  935. X{    "CHAR-EQUAL",            S, xchrieql        }, /* 263 */
  936. X{    "CHAR-NOT-EQUAL",        S, xchrineq        }, /* 264 */
  937. X{    "CHAR-NOT-LESSP",        S, xchrigeq        }, /* 265 */
  938. X{    "CHAR-GREATERP",        S, xchrigtr        }, /* 266 */
  939. X{    "UPPER-CASE-P",            S, xuppercasep        }, /* 267 */
  940. X{    "LOWER-CASE-P",            S, xlowercasep        }, /* 268 */
  941. X{    "BOTH-CASE-P",            S, xbothcasep        }, /* 269 */
  942. X{    "DIGIT-CHAR-P",            S, xdigitp        }, /* 270 */
  943. X{    "ALPHANUMERICP",        S, xalphanumericp    }, /* 271 */
  944. X{    "CHAR-UPCASE",            S, xchupcase        }, /* 272 */
  945. X{    "CHAR-DOWNCASE",        S, xchdowncase        }, /* 273 */
  946. X{    "DIGIT-CHAR",            S, xdigitchar        }, /* 274 */
  947. X{    "CHAR-CODE",            S, xcharcode        }, /* 275 */
  948. X{    "CODE-CHAR",            S, xcodechar        }, /* 276 */
  949. X{    "ENDP",                S, xendp        }, /* 277 */
  950. X{    "REMOVE-IF",            S, xremif        }, /* 278 */
  951. X{    "REMOVE-IF-NOT",        S, xremifnot        }, /* 279 */
  952. X{    "DELETE-IF",            S, xdelif        }, /* 280 */
  953. X{    "DELETE-IF-NOT",        S, xdelifnot        }, /* 281 */
  954. X{    "TRACE",            F, xtrace        }, /* 282 */
  955. X{    "UNTRACE",            F, xuntrace        }, /* 283 */
  956. X{    "SORT",                S, xsort        }, /* 284 */
  957. X{    "DEFSTRUCT",            F, xdefstruct        }, /* 285 */
  958. X{    "%STRUCT-TYPE-P",        S, xstrtypep        }, /* 286 */
  959. X{    "%MAKE-STRUCT",            S, xmkstruct        }, /* 287 */
  960. X{    "%COPY-STRUCT",            S, xcpystruct        }, /* 288 */
  961. X{    "%STRUCT-REF",            S, xstrref        }, /* 289 */
  962. X{    "%STRUCT-SET",            S, xstrset        }, /* 290 */
  963. X{    "ASIN",                S, xasin        }, /* 291 */
  964. X{    "ACOS",                S, xacos        }, /* 292 */
  965. X{    "ATAN",                S, xatan        }, /* 293 */
  966. X
  967. X    /* extra table entries */
  968. X{    NULL,                S, xnotimp        }, /* 294 */
  969. X{    NULL,                S, xnotimp        }, /* 295 */
  970. X{    NULL,                S, xnotimp        }, /* 296 */
  971. X{    NULL,                S, xnotimp        }, /* 297 */
  972. X{    NULL,                S, xnotimp        }, /* 298 */
  973. X{    NULL,                S, xnotimp        }, /* 299 */
  974. X
  975. X    /* include system dependant function pointers */
  976. X#include "osptrs.h"
  977. X
  978. X{0,0,0} /* end of table marker */
  979. X
  980. X};            
  981. X
  982. X/* xnotimp - function table entries that are currently not implemented */
  983. XLOCAL LVAL xnotimp()
  984. X{
  985. X    xlfail("function not implemented");
  986. X}
  987. X
  988. SHAR_EOF
  989. if test 16622 -ne "`wc -c 'xlftab.c'`"
  990. then
  991.     echo shar: error transmitting "'xlftab.c'" '(should have been 16622 characters)'
  992. fi
  993. echo shar: extracting "'xlglob.c'" '(2731 characters)'
  994. if test -f 'xlglob.c'
  995. then
  996.     echo shar: over-writing existing file "'xlglob.c'"
  997. fi
  998. sed 's/^X//' << \SHAR_EOF > 'xlglob.c'
  999. X/* xlglobals - xlisp global variables */
  1000. X/*    Copyright (c) 1985, by David Michael Betz
  1001. X    All Rights Reserved
  1002. X    Permission is granted for unrestricted non-commercial use    */
  1003. X
  1004. X#include "xlisp.h"
  1005. X
  1006. X/* symbols */
  1007. XLVAL true=NIL,obarray=NIL;
  1008. XLVAL s_unbound=NIL,s_dot=NIL;
  1009. XLVAL s_quote=NIL,s_function=NIL;
  1010. XLVAL s_bquote=NIL,s_comma=NIL,s_comat=NIL;
  1011. XLVAL s_evalhook=NIL,s_applyhook=NIL,s_tracelist;
  1012. XLVAL s_lambda=NIL,s_macro=NIL;
  1013. XLVAL s_stdin=NIL,s_stdout=NIL,s_stderr=NIL,s_debugio=NIL,s_traceout=NIL;
  1014. XLVAL s_rtable=NIL;
  1015. XLVAL s_tracenable=NIL,s_tlimit=NIL,s_breakenable=NIL;
  1016. XLVAL s_setf=NIL,s_car=NIL,s_cdr=NIL,s_nth=NIL,s_aref=NIL,s_get=NIL;
  1017. XLVAL s_svalue=NIL,s_sfunction=NIL,s_splist=NIL;
  1018. XLVAL s_eql=NIL,s_gcflag=NIL,s_gchook=NIL;
  1019. XLVAL s_ifmt=NIL,s_ffmt=NIL;
  1020. XLVAL s_1plus=NIL,s_2plus=NIL,s_3plus=NIL;
  1021. XLVAL s_1star=NIL,s_2star=NIL,s_3star=NIL;
  1022. XLVAL s_minus=NIL,s_printcase=NIL;
  1023. X
  1024. X/* keywords */
  1025. XLVAL k_test=NIL,k_tnot=NIL;
  1026. XLVAL k_wspace=NIL,k_const=NIL,k_nmacro=NIL,k_tmacro=NIL;
  1027. XLVAL k_sescape=NIL,k_mescape=NIL;
  1028. XLVAL k_direction=NIL,k_input=NIL,k_output=NIL;
  1029. XLVAL k_start=NIL,k_end=NIL,k_1start=NIL,k_1end=NIL;
  1030. XLVAL k_2start=NIL,k_2end=NIL,k_count=NIL,k_key=NIL;
  1031. XLVAL k_verbose=NIL,k_print=NIL;
  1032. XLVAL k_upcase=NIL,k_downcase=NIL;
  1033. X
  1034. X/* lambda list keywords */
  1035. XLVAL lk_optional=NIL,lk_rest=NIL,lk_key=NIL,lk_aux=NIL;
  1036. XLVAL lk_allow_other_keys=NIL;
  1037. X
  1038. X/* type names */
  1039. XLVAL a_subr=NIL,a_fsubr=NIL;
  1040. XLVAL a_cons=NIL,a_symbol=NIL,a_fixnum=NIL,a_flonum=NIL;
  1041. XLVAL a_string=NIL,a_object=NIL,a_stream=NIL,a_vector=NIL;
  1042. XLVAL a_closure=NIL,a_char=NIL,a_ustream=NIL;
  1043. X
  1044. X/* evaluation variables */
  1045. XLVAL **xlstack = NULL,**xlstkbase = NULL,**xlstktop = NULL;
  1046. XLVAL xlenv=NIL,xlfenv=NIL,xldenv=NIL;
  1047. X
  1048. X/* argument stack */
  1049. XLVAL *xlargstkbase = NULL;    /* argument stack base */
  1050. XLVAL *xlargstktop = NULL;    /* argument stack top */
  1051. XLVAL *xlfp = NULL;        /* argument frame pointer */
  1052. XLVAL *xlsp = NULL;        /* argument stack pointer */
  1053. XLVAL *xlargv = NULL;        /* current argument vector */
  1054. Xint xlargc = 0;            /* current argument count */
  1055. X
  1056. X/* exception handling variables */
  1057. XCONTEXT *xlcontext = NULL;    /* current exception handler */
  1058. XCONTEXT *xltarget = NULL;    /* target context (for xljump) */
  1059. XLVAL xlvalue=NIL;        /* exception value (for xljump) */
  1060. Xint xlmask=0;            /* exception type (for xljump) */
  1061. X
  1062. X/* debugging variables */
  1063. Xint xldebug = 0;        /* debug level */
  1064. Xint xlsample = 0;        /* control character sample rate */
  1065. Xint xltrcindent = 0;        /* trace indent level */
  1066. X
  1067. X/* gensym variables */
  1068. Xchar gsprefix[STRMAX+1] = { 'G',0 };    /* gensym prefix string */
  1069. Xint gsnumber = 1;        /* gensym number */
  1070. X
  1071. X/* i/o variables */
  1072. Xint xlfsize = 0;        /* flat size of current print call */
  1073. XFILE *tfp = NULL;        /* transcript file pointer */
  1074. X
  1075. X/* general purpose string buffer */
  1076. Xchar buf[STRMAX+1] = { 0 };
  1077. X
  1078. SHAR_EOF
  1079. if test 2731 -ne "`wc -c 'xlglob.c'`"
  1080. then
  1081.     echo shar: error transmitting "'xlglob.c'" '(should have been 2731 characters)'
  1082. fi
  1083. echo shar: extracting "'xlimage.c'" '(8425 characters)'
  1084. if test -f 'xlimage.c'
  1085. then
  1086.     echo shar: over-writing existing file "'xlimage.c'"
  1087. fi
  1088. sed 's/^X//' << \SHAR_EOF > 'xlimage.c'
  1089. X/* xlimage - xlisp memory image save/restore functions */
  1090. X/*    Copyright (c) 1985, by David Michael Betz
  1091. X    All Rights Reserved
  1092. X    Permission is granted for unrestricted non-commercial use    */
  1093. X
  1094. X#include "xlisp.h"
  1095. X
  1096. X#ifdef SAVERESTORE
  1097. X
  1098. X/* external variables */
  1099. Xextern LVAL obarray,xlenv,xlfenv,xldenv,s_gchook,s_gcflag;
  1100. Xextern long nnodes,nfree,total;
  1101. Xextern int anodes,nsegs,gccalls;
  1102. Xextern struct segment *segs,*lastseg,*fixseg,*charseg;
  1103. Xextern CONTEXT *xlcontext;
  1104. Xextern LVAL fnodes;
  1105. X
  1106. X/* local variables */
  1107. Xstatic OFFTYPE off,foff,doff;
  1108. Xstatic FILE *fp;
  1109. X
  1110. X/* external procedures */
  1111. Xextern SEGMENT *newsegment();
  1112. Xextern FILE *osbopen();
  1113. Xextern char *malloc();
  1114. X
  1115. X/* forward declarations */
  1116. XOFFTYPE readptr();
  1117. XOFFTYPE cvoptr();
  1118. XLVAL cviptr();
  1119. X
  1120. X/* xlisave - save the memory image */
  1121. Xint xlisave(fname)
  1122. X  char *fname;
  1123. X{
  1124. X    char fullname[STRMAX+1];
  1125. X    unsigned char *cp;
  1126. X    SEGMENT *seg;
  1127. X    int n,i,max;
  1128. X    LVAL p;
  1129. X
  1130. X    /* default the extension */
  1131. X    if (needsextension(fname)) {
  1132. X    strcpy(fullname,fname);
  1133. X    strcat(fullname,".wks");
  1134. X    fname = fullname;
  1135. X    }
  1136. X
  1137. X    /* open the output file */
  1138. X    if ((fp = osbopen(fname,"w")) == NULL)
  1139. X    return (FALSE);
  1140. X
  1141. X    /* first call the garbage collector to clean up memory */
  1142. X    gc();
  1143. X
  1144. X    /* write out the pointer to the *obarray* symbol */
  1145. X    writeptr(cvoptr(obarray));
  1146. X
  1147. X    /* setup the initial file offsets */
  1148. X    off = foff = (OFFTYPE)2;
  1149. X
  1150. X    /* write out all nodes that are still in use */
  1151. X    for (seg = segs; seg != NULL; seg = seg->sg_next) {
  1152. X    p = &seg->sg_nodes[0];
  1153. X    for (n = seg->sg_size; --n >= 0; ++p, off += 2)
  1154. X        switch (ntype(p)) {
  1155. X        case FREE:
  1156. X        break;
  1157. X        case CONS:
  1158. X        case USTREAM:
  1159. X        setoffset();
  1160. X        osbputc(p->n_type,fp);
  1161. X        writeptr(cvoptr(car(p)));
  1162. X        writeptr(cvoptr(cdr(p)));
  1163. X        foff += 2;
  1164. X        break;
  1165. X        default:
  1166. X        setoffset();
  1167. X        writenode(p);
  1168. X        break;
  1169. X        }
  1170. X    }
  1171. X
  1172. X    /* write the terminator */
  1173. X    osbputc(FREE,fp);
  1174. X    writeptr((OFFTYPE)0);
  1175. X
  1176. X    /* write out data portion of vector-like nodes */
  1177. X    for (seg = segs; seg != NULL; seg = seg->sg_next) {
  1178. X    p = &seg->sg_nodes[0];
  1179. X    for (n = seg->sg_size; --n >= 0; ++p)
  1180. X        switch (ntype(p)) {
  1181. X        case SYMBOL:
  1182. X        case OBJECT:
  1183. X        case VECTOR:
  1184. X        case CLOSURE:
  1185. X        case STRUCT:
  1186. X        max = getsize(p);
  1187. X        for (i = 0; i < max; ++i)
  1188. X            writeptr(cvoptr(getelement(p,i)));
  1189. X        break;
  1190. X        case STRING:
  1191. X        max = getslength(p);
  1192. X        for (cp = getstring(p); --max >= 0; )
  1193. X            osbputc(*cp++,fp);
  1194. X        break;
  1195. X        }
  1196. X    }
  1197. X
  1198. X    /* close the output file */
  1199. X    osclose(fp);
  1200. X
  1201. X    /* return successfully */
  1202. X    return (TRUE);
  1203. X}
  1204. X
  1205. X/* xlirestore - restore a saved memory image */
  1206. Xint xlirestore(fname)
  1207. X  char *fname;
  1208. X{
  1209. X    extern FUNDEF funtab[];
  1210. X    char fullname[STRMAX+1];
  1211. X    unsigned char *cp;
  1212. X    int n,i,max,type;
  1213. X    SEGMENT *seg;
  1214. X    LVAL p;
  1215. X
  1216. X    /* default the extension */
  1217. X    if (needsextension(fname)) {
  1218. X    strcpy(fullname,fname);
  1219. X    strcat(fullname,".wks");
  1220. X    fname = fullname;
  1221. X    }
  1222. X
  1223. X    /* open the file */
  1224. X    if ((fp = osbopen(fname,"r")) == NULL)
  1225. X    return (FALSE);
  1226. X
  1227. X    /* free the old memory image */
  1228. X    freeimage();
  1229. X
  1230. X    /* initialize */
  1231. X    off = (OFFTYPE)2;
  1232. X    total = nnodes = nfree = 0L;
  1233. X    fnodes = NIL;
  1234. X    segs = lastseg = NULL;
  1235. X    nsegs = gccalls = 0;
  1236. X    xlenv = xlfenv = xldenv = s_gchook = s_gcflag = NIL;
  1237. X    xlstack = xlstkbase + EDEPTH;
  1238. X    xlcontext = NULL;
  1239. X
  1240. X    /* create the fixnum segment */
  1241. X    if ((fixseg = newsegment(SFIXSIZE)) == NULL)
  1242. X    xlfatal("insufficient memory - fixnum segment");
  1243. X
  1244. X    /* create the character segment */
  1245. X    if ((charseg = newsegment(CHARSIZE)) == NULL)
  1246. X    xlfatal("insufficient memory - character segment");
  1247. X
  1248. X    /* read the pointer to the *obarray* symbol */
  1249. X    obarray = cviptr(readptr());
  1250. X
  1251. X    /* read each node */
  1252. X    while ((type = osbgetc(fp)) >= 0)
  1253. X    switch (type) {
  1254. X    case FREE:
  1255. X        if ((off = readptr()) == (OFFTYPE)0)
  1256. X        goto done;
  1257. X        break;
  1258. X    case CONS:
  1259. X    case USTREAM:
  1260. X        p = cviptr(off);
  1261. X        p->n_type = type;
  1262. X        p->n_flags = 0;
  1263. X        rplaca(p,cviptr(readptr()));
  1264. X        rplacd(p,cviptr(readptr()));
  1265. X        off += 2;
  1266. X        break;
  1267. X    default:
  1268. X        readnode(type,cviptr(off));
  1269. X        off += 2;
  1270. X        break;
  1271. X    }
  1272. Xdone:
  1273. X
  1274. X    /* read the data portion of vector-like nodes */
  1275. X    for (seg = segs; seg != NULL; seg = seg->sg_next) {
  1276. X    p = &seg->sg_nodes[0];
  1277. X    for (n = seg->sg_size; --n >= 0; ++p)
  1278. X        switch (ntype(p)) {
  1279. X        case SYMBOL:
  1280. X        case OBJECT:
  1281. X        case VECTOR:
  1282. X        case CLOSURE:
  1283. X        case STRUCT:
  1284. X        max = getsize(p);
  1285. X        if ((p->n_vdata = (LVAL *)malloc(max * sizeof(LVAL))) == NULL)
  1286. X            xlfatal("insufficient memory - vector");
  1287. X        total += (long)(max * sizeof(LVAL));
  1288. X        for (i = 0; i < max; ++i)
  1289. X            setelement(p,i,cviptr(readptr()));
  1290. X        break;
  1291. X        case STRING:
  1292. X        max = getslength(p);
  1293. X        if ((p->n_string = (unsigned char *)malloc(max)) == NULL)
  1294. X            xlfatal("insufficient memory - string");
  1295. X        total += (long)max;
  1296. X        for (cp = getstring(p); --max >= 0; )
  1297. X            *cp++ = osbgetc(fp);
  1298. X        break;
  1299. X        case STREAM:
  1300. X        setfile(p,NULL);
  1301. X        break;
  1302. X        case SUBR:
  1303. X        case FSUBR:
  1304. X        p->n_subr = funtab[getoffset(p)].fd_subr;
  1305. X        break;
  1306. X        }
  1307. X    }
  1308. X
  1309. X    /* close the input file */
  1310. X    osclose(fp);
  1311. X
  1312. X    /* collect to initialize the free space */
  1313. X    gc();
  1314. X
  1315. X    /* lookup all of the symbols the interpreter uses */
  1316. X    xlsymbols();
  1317. X
  1318. X    /* return successfully */
  1319. X    return (TRUE);
  1320. X}
  1321. X
  1322. X/* freeimage - free the current memory image */
  1323. XLOCAL freeimage()
  1324. X{
  1325. X    SEGMENT *seg,*next;
  1326. X    FILE *fp;
  1327. X    LVAL p;
  1328. X    int n;
  1329. X
  1330. X    /* free the data portion of vector-like nodes */
  1331. X    for (seg = segs; seg != NULL; seg = next) {
  1332. X    p = &seg->sg_nodes[0];
  1333. X    for (n = seg->sg_size; --n >= 0; ++p)
  1334. X        switch (ntype(p)) {
  1335. X        case SYMBOL:
  1336. X        case OBJECT:
  1337. X        case VECTOR:
  1338. X        case CLOSURE:
  1339. X        case STRUCT:
  1340. X        if (p->n_vsize)
  1341. X            free(p->n_vdata);
  1342. X        break;
  1343. X        case STRING:
  1344. X        if (getslength(p))
  1345. X            free(getstring(p));
  1346. X        break;
  1347. X        case STREAM:
  1348. X        if ((fp = getfile(p)) && (fp != stdin && fp != stdout))
  1349. X            osclose(getfile(p));
  1350. X        break;
  1351. X        }
  1352. X    next = seg->sg_next;
  1353. X    free(seg);
  1354. X    }
  1355. X}
  1356. X
  1357. X/* setoffset - output a positioning command if nodes have been skipped */
  1358. XLOCAL setoffset()
  1359. X{
  1360. X    if (off != foff) {
  1361. X    osbputc(FREE,fp);
  1362. X    writeptr(off);
  1363. X    foff = off;
  1364. X    }
  1365. X}
  1366. X
  1367. X/* writenode - write a node to a file */
  1368. XLOCAL writenode(node)
  1369. X  LVAL node;
  1370. X{
  1371. X    char *p = (char *)&node->n_info;
  1372. X    int n = sizeof(union ninfo);
  1373. X    osbputc(node->n_type,fp);
  1374. X    while (--n >= 0)
  1375. X    osbputc(*p++,fp);
  1376. X    foff += 2;
  1377. X}
  1378. X
  1379. X/* writeptr - write a pointer to a file */
  1380. XLOCAL writeptr(off)
  1381. X  OFFTYPE off;
  1382. X{
  1383. X    char *p = (char *)&off;
  1384. X    int n = sizeof(OFFTYPE);
  1385. X    while (--n >= 0)
  1386. X    osbputc(*p++,fp);
  1387. X}
  1388. X
  1389. X/* readnode - read a node */
  1390. XLOCAL readnode(type,node)
  1391. X  int type; LVAL node;
  1392. X{
  1393. X    char *p = (char *)&node->n_info;
  1394. X    int n = sizeof(union ninfo);
  1395. X    node->n_type = type;
  1396. X    node->n_flags = 0;
  1397. X    while (--n >= 0)
  1398. X    *p++ = osbgetc(fp);
  1399. X}
  1400. X
  1401. X/* readptr - read a pointer */
  1402. XLOCAL OFFTYPE readptr()
  1403. X{
  1404. X    OFFTYPE off;
  1405. X    char *p = (char *)&off;
  1406. X    int n = sizeof(OFFTYPE);
  1407. X    while (--n >= 0)
  1408. X    *p++ = osbgetc(fp);
  1409. X    return (off);
  1410. X}
  1411. X
  1412. X/* cviptr - convert a pointer on input */
  1413. XLOCAL LVAL cviptr(o)
  1414. X  OFFTYPE o;
  1415. X{
  1416. X    OFFTYPE off = (OFFTYPE)2;
  1417. X    SEGMENT *seg;
  1418. X
  1419. X    /* check for nil */
  1420. X    if (o == (OFFTYPE)0)
  1421. X    return ((LVAL)o);
  1422. X
  1423. X    /* compute a pointer for this offset */
  1424. X    for (seg = segs; seg != NULL; seg = seg->sg_next) {
  1425. X    if (o >= off && o < off + (OFFTYPE)(seg->sg_size << 1))
  1426. X        return (seg->sg_nodes + ((int)(o - off) >> 1));
  1427. X    off += (OFFTYPE)(seg->sg_size << 1);
  1428. X    }
  1429. X
  1430. X    /* create new segments if necessary */
  1431. X    for (;;) {
  1432. X
  1433. X    /* create the next segment */
  1434. X    if ((seg = newsegment(anodes)) == NULL)
  1435. X        xlfatal("insufficient memory - segment");
  1436. X
  1437. X    /* check to see if the offset is in this segment */
  1438. X    if (o >= off && o < off + (OFFTYPE)(seg->sg_size << 1))
  1439. X        return (seg->sg_nodes + ((int)(o - off) >> 1));
  1440. X    off += (OFFTYPE)(seg->sg_size << 1);
  1441. X    }
  1442. X}
  1443. X
  1444. X/* cvoptr - convert a pointer on output */
  1445. XLOCAL OFFTYPE cvoptr(p)
  1446. X  LVAL p;
  1447. X{
  1448. X    OFFTYPE off = (OFFTYPE)2;
  1449. X    SEGMENT *seg;
  1450. X
  1451. X    /* check for nil and small fixnums */
  1452. X    if (p == NIL)
  1453. X    return ((OFFTYPE)p);
  1454. X
  1455. X    /* compute an offset for this pointer */
  1456. X    for (seg = segs; seg != NULL; seg = seg->sg_next) {
  1457. X    if (CVPTR(p) >= CVPTR(&seg->sg_nodes[0]) &&
  1458. X        CVPTR(p) <  CVPTR(&seg->sg_nodes[0] + seg->sg_size))
  1459. X        return (off + (OFFTYPE)((p - seg->sg_nodes) << 1));
  1460. X    off += (OFFTYPE)(seg->sg_size << 1);
  1461. X    }
  1462. X
  1463. X    /* pointer not within any segment */
  1464. X    xlerror("bad pointer found during image save",p);
  1465. X}
  1466. X
  1467. X#endif
  1468. X
  1469. SHAR_EOF
  1470. if test 8425 -ne "`wc -c 'xlimage.c'`"
  1471. then
  1472.     echo shar: error transmitting "'xlimage.c'" '(should have been 8425 characters)'
  1473. fi
  1474. echo shar: extracting "'xlinit.c'" '(7703 characters)'
  1475. if test -f 'xlinit.c'
  1476. then
  1477.     echo shar: over-writing existing file "'xlinit.c'"
  1478. fi
  1479. sed 's/^X//' << \SHAR_EOF > 'xlinit.c'
  1480. X/* xlinit.c - xlisp initialization module */
  1481. X/*    Copyright (c) 1985, by David Michael Betz
  1482. X    All Rights Reserved
  1483. X    Permission is granted for unrestricted non-commercial use    */
  1484. X
  1485. X#include "xlisp.h"
  1486. X
  1487. X/* external variables */
  1488. Xextern LVAL true,s_dot,s_unbound;
  1489. Xextern LVAL s_quote,s_function,s_bquote,s_comma,s_comat;
  1490. Xextern LVAL s_lambda,s_macro;
  1491. Xextern LVAL s_stdin,s_stdout,s_stderr,s_debugio,s_traceout;
  1492. Xextern LVAL s_evalhook,s_applyhook,s_tracelist;
  1493. Xextern LVAL s_tracenable,s_tlimit,s_breakenable;
  1494. Xextern LVAL s_setf,s_car,s_cdr,s_nth,s_aref,s_get,s_eql;
  1495. Xextern LVAL s_svalue,s_sfunction,s_splist;
  1496. Xextern LVAL s_rtable,k_wspace,k_const,k_nmacro,k_tmacro;
  1497. Xextern LVAL k_sescape,k_mescape;
  1498. Xextern LVAL s_ifmt,s_ffmt,s_printcase;
  1499. Xextern LVAL s_1plus,s_2plus,s_3plus,s_1star,s_2star,s_3star,s_minus;
  1500. Xextern LVAL k_test,k_tnot;
  1501. Xextern LVAL k_direction,k_input,k_output;
  1502. Xextern LVAL k_start,k_end,k_1start,k_1end,k_2start,k_2end;
  1503. Xextern LVAL k_verbose,k_print,k_count,k_key,k_upcase,k_downcase;
  1504. Xextern LVAL lk_optional,lk_rest,lk_key,lk_aux,lk_allow_other_keys;
  1505. Xextern LVAL a_subr,a_fsubr,a_cons,a_symbol;
  1506. Xextern LVAL a_fixnum,a_flonum,a_string,a_stream,a_object;
  1507. Xextern LVAL a_vector,a_closure,a_char,a_ustream;
  1508. Xextern LVAL s_gcflag,s_gchook;
  1509. Xextern FUNDEF funtab[];
  1510. X
  1511. X/* xlinit - xlisp initialization routine */
  1512. Xxlinit()
  1513. X{
  1514. X    /* initialize xlisp (must be in this order) */
  1515. X    xlminit();    /* initialize xldmem.c */
  1516. X    xldinit();    /* initialize xldbug.c */
  1517. X
  1518. X    /* finish initializing */
  1519. X#ifdef SAVERESTORE
  1520. X    if (!xlirestore("xlisp.wks"))
  1521. X#endif
  1522. X    initwks();
  1523. X}
  1524. X
  1525. X/* initwks - build an initial workspace */
  1526. XLOCAL initwks()
  1527. X{
  1528. X    FUNDEF *p;
  1529. X    int i;
  1530. X    
  1531. X    xlsinit();    /* initialize xlsym.c */
  1532. X    xlsymbols();/* enter all symbols used by the interpreter */
  1533. X    xlrinit();    /* initialize xlread.c */
  1534. X    xloinit();    /* initialize xlobj.c */
  1535. X
  1536. X    /* setup defaults */
  1537. X    setvalue(s_evalhook,NIL);        /* no evalhook function */
  1538. X    setvalue(s_applyhook,NIL);        /* no applyhook function */
  1539. X    setvalue(s_tracelist,NIL);        /* no functions being traced */
  1540. X    setvalue(s_tracenable,NIL);        /* traceback disabled */
  1541. X    setvalue(s_tlimit,NIL);         /* trace limit infinite */
  1542. X    setvalue(s_breakenable,NIL);    /* don't enter break loop on errors */
  1543. X    setvalue(s_gcflag,NIL);        /* don't show gc information */
  1544. X    setvalue(s_gchook,NIL);        /* no gc hook active */
  1545. X    setvalue(s_ifmt,cvstring(IFMT));    /* integer print format */
  1546. X    setvalue(s_ffmt,cvstring("%g"));    /* float print format */
  1547. X    setvalue(s_printcase,k_upcase);    /* upper case output of symbols */
  1548. X
  1549. X    /* install the built-in functions and special forms */
  1550. X    for (i = 0, p = funtab; p->fd_subr != NULL; ++i, ++p)
  1551. X    if (p->fd_name)
  1552. X        xlsubr(p->fd_name,p->fd_type,p->fd_subr,i);
  1553. X
  1554. X    /* add some synonyms */
  1555. X    setfunction(xlenter("NOT"),getfunction(xlenter("NULL")));
  1556. X    setfunction(xlenter("FIRST"),getfunction(xlenter("CAR")));
  1557. X    setfunction(xlenter("SECOND"),getfunction(xlenter("CADR")));
  1558. X    setfunction(xlenter("THIRD"),getfunction(xlenter("CADDR")));
  1559. X    setfunction(xlenter("FOURTH"),getfunction(xlenter("CADDDR")));
  1560. X    setfunction(xlenter("REST"),getfunction(xlenter("CDR")));
  1561. X}
  1562. X
  1563. X/* xlsymbols - enter all of the symbols used by the interpreter */
  1564. Xxlsymbols()
  1565. X{
  1566. X    LVAL sym;
  1567. X
  1568. X    /* enter the unbound variable indicator (must be first) */
  1569. X    s_unbound = xlenter("*UNBOUND*");
  1570. X    setvalue(s_unbound,s_unbound);
  1571. X
  1572. X    /* enter the 't' symbol */
  1573. X    true = xlenter("T");
  1574. X    setvalue(true,true);
  1575. X
  1576. X    /* enter some important symbols */
  1577. X    s_dot    = xlenter(".");
  1578. X    s_quote    = xlenter("QUOTE");
  1579. X    s_function    = xlenter("FUNCTION");
  1580. X    s_bquote    = xlenter("BACKQUOTE");
  1581. X    s_comma    = xlenter("COMMA");
  1582. X    s_comat    = xlenter("COMMA-AT");
  1583. X    s_lambda    = xlenter("LAMBDA");
  1584. X    s_macro    = xlenter("MACRO");
  1585. X    s_eql    = xlenter("EQL");
  1586. X    s_ifmt    = xlenter("*INTEGER-FORMAT*");
  1587. X    s_ffmt    = xlenter("*FLOAT-FORMAT*");
  1588. X
  1589. X    /* symbols set by the read-eval-print loop */
  1590. X    s_1plus    = xlenter("+");
  1591. X    s_2plus    = xlenter("++");
  1592. X    s_3plus    = xlenter("+++");
  1593. X    s_1star    = xlenter("*");
  1594. X    s_2star    = xlenter("**");
  1595. X    s_3star    = xlenter("***");
  1596. X    s_minus    = xlenter("-");
  1597. X
  1598. X    /* enter setf place specifiers */
  1599. X    s_setf    = xlenter("*SETF*");
  1600. X    s_car    = xlenter("CAR");
  1601. X    s_cdr    = xlenter("CDR");
  1602. X    s_nth    = xlenter("NTH");
  1603. X    s_aref    = xlenter("AREF");
  1604. X    s_get    = xlenter("GET");
  1605. X    s_svalue    = xlenter("SYMBOL-VALUE");
  1606. X    s_sfunction    = xlenter("SYMBOL-FUNCTION");
  1607. X    s_splist    = xlenter("SYMBOL-PLIST");
  1608. X
  1609. X    /* enter the readtable variable and keywords */
  1610. X    s_rtable    = xlenter("*READTABLE*");
  1611. X    k_wspace    = xlenter(":WHITE-SPACE");
  1612. X    k_const    = xlenter(":CONSTITUENT");
  1613. X    k_nmacro    = xlenter(":NMACRO");
  1614. X    k_tmacro    = xlenter(":TMACRO");
  1615. X    k_sescape    = xlenter(":SESCAPE");
  1616. X    k_mescape    = xlenter(":MESCAPE");
  1617. X
  1618. X    /* enter parameter list keywords */
  1619. X    k_test    = xlenter(":TEST");
  1620. X    k_tnot    = xlenter(":TEST-NOT");
  1621. X
  1622. X    /* "open" keywords */
  1623. X    k_direction = xlenter(":DIRECTION");
  1624. X    k_input     = xlenter(":INPUT");
  1625. X    k_output    = xlenter(":OUTPUT");
  1626. X
  1627. X    /* enter *print-case* symbol and keywords */
  1628. X    s_printcase = xlenter("*PRINT-CASE*");
  1629. X    k_upcase    = xlenter(":UPCASE");
  1630. X    k_downcase  = xlenter(":DOWNCASE");
  1631. X
  1632. X    /* other keywords */
  1633. X    k_start    = xlenter(":START");
  1634. X    k_end    = xlenter(":END");
  1635. X    k_1start    = xlenter(":START1");
  1636. X    k_1end    = xlenter(":END1");
  1637. X    k_2start    = xlenter(":START2");
  1638. X    k_2end    = xlenter(":END2");
  1639. X    k_verbose    = xlenter(":VERBOSE");
  1640. X    k_print    = xlenter(":PRINT");
  1641. X    k_count    = xlenter(":COUNT");
  1642. X    k_key    = xlenter(":KEY");
  1643. X
  1644. X    /* enter lambda list keywords */
  1645. X    lk_optional    = xlenter("&OPTIONAL");
  1646. X    lk_rest    = xlenter("&REST");
  1647. X    lk_key    = xlenter("&KEY");
  1648. X    lk_aux    = xlenter("&AUX");
  1649. X    lk_allow_other_keys = xlenter("&ALLOW-OTHER-KEYS");
  1650. X
  1651. X    /* enter *standard-input*, *standard-output* and *error-output* */
  1652. X    s_stdin = xlenter("*STANDARD-INPUT*");
  1653. X    setvalue(s_stdin,cvfile(stdin));
  1654. X    s_stdout = xlenter("*STANDARD-OUTPUT*");
  1655. X    setvalue(s_stdout,cvfile(stdout));
  1656. X    s_stderr = xlenter("*ERROR-OUTPUT*");
  1657. X    setvalue(s_stderr,cvfile(stderr));
  1658. X
  1659. X    /* enter *debug-io* and *trace-output* */
  1660. X    s_debugio = xlenter("*DEBUG-IO*");
  1661. X    setvalue(s_debugio,getvalue(s_stderr));
  1662. X    s_traceout = xlenter("*TRACE-OUTPUT*");
  1663. X    setvalue(s_traceout,getvalue(s_stderr));
  1664. X
  1665. X    /* enter the eval and apply hook variables */
  1666. X    s_evalhook = xlenter("*EVALHOOK*");
  1667. X    s_applyhook = xlenter("*APPLYHOOK*");
  1668. X
  1669. X    /* enter the symbol pointing to the list of functions being traced */
  1670. X    s_tracelist = xlenter("*TRACELIST*");
  1671. X
  1672. X    /* enter the error traceback and the error break enable flags */
  1673. X    s_tracenable = xlenter("*TRACENABLE*");
  1674. X    s_tlimit = xlenter("*TRACELIMIT*");
  1675. X    s_breakenable = xlenter("*BREAKENABLE*");
  1676. X
  1677. X    /* enter a symbol to control printing of garbage collection messages */
  1678. X    s_gcflag = xlenter("*GC-FLAG*");
  1679. X    s_gchook = xlenter("*GC-HOOK*");
  1680. X
  1681. X    /* enter a copyright notice into the oblist */
  1682. X    sym = xlenter("**Copyright-1988-by-David-Betz**");
  1683. X    setvalue(sym,true);
  1684. X
  1685. X    /* enter type names */
  1686. X    a_subr    = xlenter("SUBR");
  1687. X    a_fsubr    = xlenter("FSUBR");
  1688. X    a_cons    = xlenter("CONS");
  1689. X    a_symbol    = xlenter("SYMBOL");
  1690. X    a_fixnum    = xlenter("FIXNUM");
  1691. X    a_flonum    = xlenter("FLONUM");
  1692. X    a_string    = xlenter("STRING");
  1693. X    a_object    = xlenter("OBJECT");
  1694. X    a_stream    = xlenter("FILE-STREAM");
  1695. X    a_vector    = xlenter("ARRAY");
  1696. X    a_closure    = xlenter("CLOSURE");
  1697. X    a_char      = xlenter("CHARACTER");
  1698. X    a_ustream    = xlenter("UNNAMED-STREAM");
  1699. X
  1700. X    /* add the object-oriented programming symbols and os specific stuff */
  1701. X    obsymbols();    /* object-oriented programming symbols */
  1702. X    ossymbols();    /* os specific symbols */
  1703. X}
  1704. X
  1705. SHAR_EOF
  1706. if test 7703 -ne "`wc -c 'xlinit.c'`"
  1707. then
  1708.     echo shar: error transmitting "'xlinit.c'" '(should have been 7703 characters)'
  1709. fi
  1710. echo shar: extracting "'xlio.c'" '(4057 characters)'
  1711. if test -f 'xlio.c'
  1712. then
  1713.     echo shar: over-writing existing file "'xlio.c'"
  1714. fi
  1715. sed 's/^X//' << \SHAR_EOF > 'xlio.c'
  1716. X/* xlio - xlisp i/o routines */
  1717. X/*    Copyright (c) 1985, by David Michael Betz
  1718. X    All Rights Reserved
  1719. X    Permission is granted for unrestricted non-commercial use    */
  1720. X
  1721. X#include "xlisp.h"
  1722. X
  1723. X/* external variables */
  1724. Xextern LVAL s_stdin,s_stdout,s_stderr,s_debugio,s_traceout,s_unbound;
  1725. Xextern int xlfsize;
  1726. X
  1727. X/* xlgetc - get a character from a file or stream */
  1728. Xint xlgetc(fptr)
  1729. X  LVAL fptr;
  1730. X{
  1731. X    LVAL lptr,cptr;
  1732. X    FILE *fp;
  1733. X    int ch;
  1734. X
  1735. X    /* check for input from nil */
  1736. X    if (fptr == NIL)
  1737. X    ch = EOF;
  1738. X
  1739. X    /* otherwise, check for input from a stream */
  1740. X    else if (ustreamp(fptr)) {
  1741. X    if ((lptr = gethead(fptr)) == NIL)
  1742. X        ch = EOF;
  1743. X    else {
  1744. X        if (!consp(lptr) || (cptr = car(lptr)) == NIL || !charp(cptr))
  1745. X        xlfail("bad stream");
  1746. X        sethead(fptr,lptr = cdr(lptr));
  1747. X        if (lptr == NIL)
  1748. X        settail(fptr,NIL);
  1749. X        ch = getchcode(cptr);
  1750. X    }
  1751. X    }
  1752. X
  1753. X    /* otherwise, check for a buffered character */
  1754. X    else if (ch = getsavech(fptr))
  1755. X    setsavech(fptr,'\0');
  1756. X
  1757. X    /* otherwise, check for terminal input or file input */
  1758. X    else {
  1759. X    fp = getfile(fptr);
  1760. X    if (fp == stdin || fp == stderr)
  1761. X        ch = ostgetc();
  1762. X    else
  1763. X        ch = osagetc(fp);
  1764. X    }
  1765. X
  1766. X    /* return the character */
  1767. X    return (ch);
  1768. X}
  1769. X
  1770. X/* xlungetc - unget a character */
  1771. Xxlungetc(fptr,ch)
  1772. X  LVAL fptr; int ch;
  1773. X{
  1774. X    LVAL lptr;
  1775. X    
  1776. X    /* check for ungetc from nil */
  1777. X    if (fptr == NIL)
  1778. X    ;
  1779. X    
  1780. X    /* otherwise, check for ungetc to a stream */
  1781. X    if (ustreamp(fptr)) {
  1782. X    if (ch != EOF) {
  1783. X        lptr = cons(cvchar(ch),gethead(fptr));
  1784. X        if (gethead(fptr) == NIL)
  1785. X        settail(fptr,lptr);
  1786. X        sethead(fptr,lptr);
  1787. X    }
  1788. X    }
  1789. X    
  1790. X    /* otherwise, it must be a file */
  1791. X    else
  1792. X    setsavech(fptr,ch);
  1793. X}
  1794. X
  1795. X/* xlpeek - peek at a character from a file or stream */
  1796. Xint xlpeek(fptr)
  1797. X  LVAL fptr;
  1798. X{
  1799. X    LVAL lptr,cptr;
  1800. X    int ch;
  1801. X
  1802. X    /* check for input from nil */
  1803. X    if (fptr == NIL)
  1804. X    ch = EOF;
  1805. X
  1806. X    /* otherwise, check for input from a stream */
  1807. X    else if (ustreamp(fptr)) {
  1808. X    if ((lptr = gethead(fptr)) == NIL)
  1809. X        ch = EOF;
  1810. X    else {
  1811. X        if (!consp(lptr) || (cptr = car(lptr)) == NIL || !charp(cptr))
  1812. X        xlfail("bad stream");
  1813. X        ch = getchcode(cptr);
  1814. X    }
  1815. X    }
  1816. X
  1817. X    /* otherwise, get the next file character and save it */
  1818. X    else {
  1819. X    ch = xlgetc(fptr);
  1820. X    setsavech(fptr,ch);
  1821. X    }
  1822. X
  1823. X    /* return the character */
  1824. X    return (ch);
  1825. X}
  1826. X
  1827. X/* xlputc - put a character to a file or stream */
  1828. Xxlputc(fptr,ch)
  1829. X  LVAL fptr; int ch;
  1830. X{
  1831. X    LVAL lptr;
  1832. X    FILE *fp;
  1833. X
  1834. X    /* count the character */
  1835. X    ++xlfsize;
  1836. X
  1837. X    /* check for output to nil */
  1838. X    if (fptr == NIL)
  1839. X    ;
  1840. X
  1841. X    /* otherwise, check for output to an unnamed stream */
  1842. X    else if (ustreamp(fptr)) {
  1843. X    lptr = consa(cvchar(ch));
  1844. X    if (gettail(fptr))
  1845. X        rplacd(gettail(fptr),lptr);
  1846. X    else
  1847. X        sethead(fptr,lptr);
  1848. X    settail(fptr,lptr);
  1849. X    }
  1850. X
  1851. X    /* otherwise, check for terminal output or file output */
  1852. X    else {
  1853. X    fp = getfile(fptr);
  1854. X    if (fp == stdout || fp == stderr)
  1855. X        ostputc(ch);
  1856. X    else
  1857. X        osaputc(ch,fp);
  1858. X    }
  1859. X}
  1860. X
  1861. X/* xlflush - flush the input buffer */
  1862. Xint xlflush()
  1863. X{
  1864. X    osflush();
  1865. X}
  1866. X
  1867. X/* stdprint - print to *standard-output* */
  1868. Xstdprint(expr)
  1869. X  LVAL expr;
  1870. X{
  1871. X    xlprint(getvalue(s_stdout),expr,TRUE);
  1872. X    xlterpri(getvalue(s_stdout));
  1873. X}
  1874. X
  1875. X/* stdputstr - print a string to *standard-output* */
  1876. Xstdputstr(str)
  1877. X  char *str;
  1878. X{
  1879. X    xlputstr(getvalue(s_stdout),str);
  1880. X}
  1881. X
  1882. X/* errprint - print to *error-output* */
  1883. Xerrprint(expr)
  1884. X  LVAL expr;
  1885. X{
  1886. X    xlprint(getvalue(s_stderr),expr,TRUE);
  1887. X    xlterpri(getvalue(s_stderr));
  1888. X}
  1889. X
  1890. X/* errputstr - print a string to *error-output* */
  1891. Xerrputstr(str)
  1892. X  char *str;
  1893. X{
  1894. X    xlputstr(getvalue(s_stderr),str);
  1895. X}
  1896. X
  1897. X/* dbgprint - print to *debug-io* */
  1898. Xdbgprint(expr)
  1899. X  LVAL expr;
  1900. X{
  1901. X    xlprint(getvalue(s_debugio),expr,TRUE);
  1902. X    xlterpri(getvalue(s_debugio));
  1903. X}
  1904. X
  1905. X/* dbgputstr - print a string to *debug-io* */
  1906. Xdbgputstr(str)
  1907. X  char *str;
  1908. X{
  1909. X    xlputstr(getvalue(s_debugio),str);
  1910. X}
  1911. X
  1912. X/* trcprin1 - print to *trace-output* */
  1913. Xtrcprin1(expr)
  1914. X  LVAL expr;
  1915. X{
  1916. X    xlprint(getvalue(s_traceout),expr,TRUE);
  1917. X}
  1918. X
  1919. X/* trcputstr - print a string to *trace-output* */
  1920. Xtrcputstr(str)
  1921. X  char *str;
  1922. X{
  1923. X    xlputstr(getvalue(s_traceout),str);
  1924. X}
  1925. X
  1926. X
  1927. SHAR_EOF
  1928. if test 4057 -ne "`wc -c 'xlio.c'`"
  1929. then
  1930.     echo shar: error transmitting "'xlio.c'" '(should have been 4057 characters)'
  1931. fi
  1932. echo shar: extracting "'xlisp.c'" '(3657 characters)'
  1933. if test -f 'xlisp.c'
  1934. then
  1935.     echo shar: over-writing existing file "'xlisp.c'"
  1936. fi
  1937. sed 's/^X//' << \SHAR_EOF > 'xlisp.c'
  1938. X/* xlisp.c - a small implementation of lisp with object-oriented programming */
  1939. X/*    Copyright (c) 1987, by David Michael Betz
  1940. X    All Rights Reserved
  1941. X    Permission is granted for unrestricted non-commercial use    */
  1942. X
  1943. X#include "xlisp.h"
  1944. X
  1945. X/* define the banner line string */
  1946. X#define BANNER    "XLISP version 2.1, Copyright (c) 1989, by David Betz"
  1947. X
  1948. X/* global variables */
  1949. Xjmp_buf top_level;
  1950. X
  1951. X/* external variables */
  1952. Xextern LVAL s_stdin,s_evalhook,s_applyhook;
  1953. Xextern LVAL s_1plus,s_2plus,s_3plus,s_1star,s_2star,s_3star,s_minus;
  1954. Xextern int xltrcindent;
  1955. Xextern int xldebug;
  1956. Xextern LVAL true;
  1957. Xextern char buf[];
  1958. Xextern FILE *tfp;
  1959. X
  1960. X/* external routines */
  1961. Xextern FILE *osaopen();
  1962. X
  1963. X/* main - the main routine */
  1964. Xmain(argc,argv)
  1965. X  int argc; char *argv[];
  1966. X{
  1967. X    char *transcript;
  1968. X    CONTEXT cntxt;
  1969. X    int verbose,i;
  1970. X    LVAL expr;
  1971. X
  1972. X    /* setup default argument values */
  1973. X    transcript = NULL;
  1974. X    verbose = FALSE;
  1975. X
  1976. X    /* parse the argument list switches */
  1977. X#ifndef LSC
  1978. X    for (i = 1; i < argc; ++i)
  1979. X    if (argv[i][0] == '-')
  1980. X        switch(argv[i][1]) {
  1981. X        case 't':
  1982. X        case 'T':
  1983. X        transcript = &argv[i][2];
  1984. X        break;
  1985. X        case 'v':
  1986. X        case 'V':
  1987. X        verbose = TRUE;
  1988. X        break;
  1989. X        }
  1990. X#endif
  1991. X
  1992. X    /* initialize and print the banner line */
  1993. X    osinit(BANNER);
  1994. X
  1995. X    /* setup initialization error handler */
  1996. X    xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,(LVAL)1);
  1997. X    if (setjmp(cntxt.c_jmpbuf))
  1998. X    xlfatal("fatal initialization error");
  1999. X    if (setjmp(top_level))
  2000. X    xlfatal("RESTORE not allowed during initialization");
  2001. X
  2002. X    /* initialize xlisp */
  2003. X    xlinit();
  2004. X    xlend(&cntxt);
  2005. X
  2006. X    /* reset the error handler */
  2007. X    xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,true);
  2008. X
  2009. X    /* open the transcript file */
  2010. X    if (transcript && (tfp = osaopen(transcript,"w")) == NULL) {
  2011. X    sprintf(buf,"error: can't open transcript file: %s",transcript);
  2012. X    stdputstr(buf);
  2013. X    }
  2014. X
  2015. X    /* load "init.lsp" */
  2016. X    if (setjmp(cntxt.c_jmpbuf) == 0)
  2017. X    xlload("init.lsp",TRUE,FALSE);
  2018. X
  2019. X    /* load any files mentioned on the command line */
  2020. X    if (setjmp(cntxt.c_jmpbuf) == 0)
  2021. X    for (i = 1; i < argc; i++)
  2022. X        if (argv[i][0] != '-' && !xlload(argv[i],TRUE,verbose))
  2023. X        xlerror("can't load file",cvstring(argv[i]));
  2024. X
  2025. X    /* target for restore */
  2026. X    if (setjmp(top_level))
  2027. X    xlbegin(&cntxt,CF_TOPLEVEL|CF_CLEANUP|CF_BRKLEVEL,true);
  2028. X
  2029. X    /* protect some pointers */
  2030. X    xlsave1(expr);
  2031. X
  2032. X    /* main command processing loop */
  2033. X    for (;;) {
  2034. X
  2035. X    /* setup the error return */
  2036. X    if (setjmp(cntxt.c_jmpbuf)) {
  2037. X        setvalue(s_evalhook,NIL);
  2038. X        setvalue(s_applyhook,NIL);
  2039. X        xltrcindent = 0;
  2040. X        xldebug = 0;
  2041. X        xlflush();
  2042. X    }
  2043. X
  2044. X    /* print a prompt */
  2045. X    stdputstr("> ");
  2046. X
  2047. X    /* read an expression */
  2048. X    if (!xlread(getvalue(s_stdin),&expr,FALSE))
  2049. X        break;
  2050. X
  2051. X    /* save the input expression */
  2052. X    xlrdsave(expr);
  2053. X
  2054. X    /* evaluate the expression */
  2055. X    expr = xleval(expr);
  2056. X
  2057. X    /* save the result */
  2058. X    xlevsave(expr);
  2059. X
  2060. X    /* print it */
  2061. X    stdprint(expr);
  2062. X    }
  2063. X    xlend(&cntxt);
  2064. X
  2065. X    /* clean up */
  2066. X    wrapup();
  2067. X}
  2068. X
  2069. X/* xlrdsave - save the last expression returned by the reader */
  2070. Xxlrdsave(expr)
  2071. X  LVAL expr;
  2072. X{
  2073. X    setvalue(s_3plus,getvalue(s_2plus));
  2074. X    setvalue(s_2plus,getvalue(s_1plus));
  2075. X    setvalue(s_1plus,getvalue(s_minus));
  2076. X    setvalue(s_minus,expr);
  2077. X}
  2078. X
  2079. X/* xlevsave - save the last expression returned by the evaluator */
  2080. Xxlevsave(expr)
  2081. X  LVAL expr;
  2082. X{
  2083. X    setvalue(s_3star,getvalue(s_2star));
  2084. X    setvalue(s_2star,getvalue(s_1star));
  2085. X    setvalue(s_1star,expr);
  2086. X}
  2087. X
  2088. X/* xlfatal - print a fatal error message and exit */
  2089. Xxlfatal(msg)
  2090. X  char *msg;
  2091. X{
  2092. X    oserror(msg);
  2093. X    wrapup();
  2094. X}
  2095. X
  2096. X/* wrapup - clean up and exit to the operating system */
  2097. Xwrapup()
  2098. X{
  2099. X    if (tfp)
  2100. X    osclose(tfp);
  2101. X    osfinish();
  2102. X    exit(0);
  2103. X}
  2104. X
  2105. SHAR_EOF
  2106. if test 3657 -ne "`wc -c 'xlisp.c'`"
  2107. then
  2108.     echo shar: error transmitting "'xlisp.c'" '(should have been 3657 characters)'
  2109. fi
  2110. echo shar: extracting "'xlisp.h'" '(9630 characters)'
  2111. if test -f 'xlisp.h'
  2112. then
  2113.     echo shar: over-writing existing file "'xlisp.h'"
  2114. fi
  2115. sed 's/^X//' << \SHAR_EOF > 'xlisp.h'
  2116. X/* xlisp - a small subset of lisp */
  2117. X/*    Copyright (c) 1985, by David Michael Betz
  2118. X    All Rights Reserved
  2119. X    Permission is granted for unrestricted non-commercial use    */
  2120. X
  2121. X/* system specific definitions */
  2122. X#define _TURBOC_
  2123. X
  2124. X#include <stdio.h>
  2125. X#include <ctype.h>
  2126. X#include <setjmp.h>
  2127. X
  2128. X/* NNODES    number of nodes to allocate in each request (1000) */
  2129. X/* EDEPTH    evaluation stack depth (2000) */
  2130. X/* ADEPTH    argument stack depth (1000) */
  2131. X/* FORWARD    type of a forward declaration () */
  2132. X/* LOCAL    type of a local function (static) */
  2133. X/* AFMT        printf format for addresses ("%x") */
  2134. X/* FIXTYPE    data type for fixed point numbers (long) */
  2135. X/* ITYPE    fixed point input conversion routine type (long atol()) */
  2136. X/* ICNV        fixed point input conversion routine (atol) */
  2137. X/* IFMT        printf format for fixed point numbers ("%ld") */
  2138. X/* FLOTYPE    data type for floating point numbers (float) */
  2139. X/* OFFTYPE    number the size of an address (int) */
  2140. X
  2141. X/* for the Turbo C compiler - MS-DOS, large model */
  2142. X#ifdef _TURBOC_
  2143. X#define NNODES        2000
  2144. X#define AFMT        "%lx"
  2145. X#define OFFTYPE        long
  2146. X#define SAVERESTORE
  2147. X#endif
  2148. X
  2149. X/* for the AZTEC C compiler - MS-DOS, large model */
  2150. X#ifdef AZTEC_LM
  2151. X#define NNODES        2000
  2152. X#define AFMT        "%lx"
  2153. X#define OFFTYPE        long
  2154. X#define CVPTR(x)    ptrtoabs(x)
  2155. X#define NIL        (void *)0
  2156. Xextern long ptrtoabs();
  2157. X#define SAVERESTORE
  2158. X#endif
  2159. X
  2160. X/* for the AZTEC C compiler - Macintosh */
  2161. X#ifdef AZTEC_MAC
  2162. X#define NNODES        2000
  2163. X#define AFMT        "%lx"
  2164. X#define OFFTYPE        long
  2165. X#define NIL        (void *)0
  2166. X#define SAVERESTORE
  2167. X#endif
  2168. X
  2169. X/* for the AZTEC C compiler - Amiga */
  2170. X#ifdef AZTEC_AMIGA
  2171. X#define NNODES        2000
  2172. X#define AFMT        "%lx"
  2173. X#define OFFTYPE        long
  2174. X#define NIL        (void *)0
  2175. X#define SAVERESTORE
  2176. X#endif
  2177. X
  2178. X/* for the Lightspeed C compiler - Macintosh */
  2179. X#ifdef LSC
  2180. X#define NNODES        2000
  2181. X#define AFMT        "%lx"
  2182. X#define OFFTYPE        long
  2183. X#define NIL        (void *)0
  2184. X#define SAVERESTORE
  2185. X#endif
  2186. X
  2187. X/* for the Microsoft C compiler - MS-DOS, large model */
  2188. X#ifdef MSC
  2189. X#define NNODES        2000
  2190. X#define AFMT        "%lx"
  2191. X#define OFFTYPE        long
  2192. X#endif
  2193. X
  2194. X/* for the Mark Williams C compiler - Atari ST */
  2195. X#ifdef MWC
  2196. X#define AFMT        "%lx"
  2197. X#define OFFTYPE        long
  2198. X#endif
  2199. X
  2200. X/* for the Lattice C compiler - Atari ST */
  2201. X#ifdef LATTICE
  2202. X#define FIXTYPE        int
  2203. X#define ITYPE        int atoi()
  2204. X#define ICNV(n)        atoi(n)
  2205. X#define IFMT        "%d"
  2206. X#endif
  2207. X
  2208. X/* for the Digital Research C compiler - Atari ST */
  2209. X#ifdef DR
  2210. X#define LOCAL
  2211. X#define AFMT        "%lx"
  2212. X#define OFFTYPE        long
  2213. X#undef NULL
  2214. X#define NULL        0L
  2215. X#endif
  2216. X
  2217. X/* default important definitions */
  2218. X#ifndef NNODES
  2219. X#define NNODES        1000
  2220. X#endif
  2221. X#ifndef EDEPTH
  2222. X#define EDEPTH        2000
  2223. X#endif
  2224. X#ifndef ADEPTH
  2225. X#define ADEPTH        1000
  2226. X#endif
  2227. X#ifndef FORWARD
  2228. X#define FORWARD
  2229. X#endif
  2230. X#ifndef LOCAL
  2231. X#define LOCAL        static
  2232. X#endif
  2233. X#ifndef AFMT
  2234. X#define AFMT        "%x"
  2235. X#endif
  2236. X#ifndef FIXTYPE
  2237. X#define FIXTYPE        long
  2238. X#endif
  2239. X#ifndef ITYPE
  2240. X#define ITYPE        long atol()
  2241. X#endif
  2242. X#ifndef ICNV
  2243. X#define ICNV(n)        atol(n)
  2244. X#endif
  2245. X#ifndef IFMT
  2246. X#define IFMT        "%ld"
  2247. X#endif
  2248. X#ifndef FLOTYPE
  2249. X#define FLOTYPE        double
  2250. X#endif
  2251. X#ifndef OFFTYPE
  2252. X#define OFFTYPE        int
  2253. X#endif
  2254. X#ifndef CVPTR
  2255. X#define CVPTR(x)    (x)
  2256. X#endif
  2257. X#ifndef UCHAR
  2258. X#define UCHAR        unsigned char
  2259. X#endif
  2260. X
  2261. X/* useful definitions */
  2262. X#define TRUE    1
  2263. X#define FALSE    0
  2264. X#ifndef NIL
  2265. X#define NIL    (LVAL )0
  2266. X#endif
  2267. X
  2268. X/* include the dynamic memory definitions */
  2269. X#include "xldmem.h"
  2270. X
  2271. X/* program limits */
  2272. X#define STRMAX        100        /* maximum length of a string constant */
  2273. X#define HSIZE        199        /* symbol hash table size */
  2274. X#define SAMPLE        100        /* control character sample rate */
  2275. X
  2276. X/* function table offsets for the initialization functions */
  2277. X#define FT_RMHASH    0
  2278. X#define FT_RMQUOTE    1
  2279. X#define FT_RMDQUOTE    2
  2280. X#define FT_RMBQUOTE    3
  2281. X#define FT_RMCOMMA    4
  2282. X#define FT_RMLPAR    5
  2283. X#define FT_RMRPAR    6
  2284. X#define FT_RMSEMI    7
  2285. X#define FT_CLNEW    10
  2286. X#define FT_CLISNEW    11
  2287. X#define FT_CLANSWER    12
  2288. X#define FT_OBISNEW    13
  2289. X#define FT_OBCLASS    14
  2290. X#define FT_OBSHOW    15
  2291. X    
  2292. X/* macro to push a value onto the argument stack */
  2293. X#define pusharg(x)    {if (xlsp >= xlargstktop) xlargstkoverflow();\
  2294. X             *xlsp++ = (x);}
  2295. X
  2296. X/* macros to protect pointers */
  2297. X#define xlstkcheck(n)    {if (xlstack - (n) < xlstkbase) xlstkoverflow();}
  2298. X#define xlsave(n)    {*--xlstack = &n; n = NIL;}
  2299. X#define xlprotect(n)    {*--xlstack = &n;}
  2300. X
  2301. X/* check the stack and protect a single pointer */
  2302. X#define xlsave1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  2303. X                         *--xlstack = &n; n = NIL;}
  2304. X#define xlprot1(n)    {if (xlstack <= xlstkbase) xlstkoverflow();\
  2305. X                         *--xlstack = &n;}
  2306. X
  2307. X/* macros to pop pointers off the stack */
  2308. X#define xlpop()        {++xlstack;}
  2309. X#define xlpopn(n)    {xlstack+=(n);}
  2310. X
  2311. X/* macros to manipulate the lexical environment */
  2312. X#define xlframe(e)    cons(NIL,e)
  2313. X#define xlbind(s,v)    xlpbind(s,v,xlenv)
  2314. X#define xlfbind(s,v)    xlpbind(s,v,xlfenv);
  2315. X#define xlpbind(s,v,e)    {rplaca(e,cons(cons(s,v),car(e)));}
  2316. X
  2317. X/* macros to manipulate the dynamic environment */
  2318. X#define xldbind(s,v)    {xldenv = cons(cons(s,getvalue(s)),xldenv);\
  2319. X             setvalue(s,v);}
  2320. X#define xlunbind(e)    {for (; xldenv != (e); xldenv = cdr(xldenv))\
  2321. X               setvalue(car(car(xldenv)),cdr(car(xldenv)));}
  2322. X
  2323. X/* type predicates */                   
  2324. X#define atom(x)        ((x) == NIL || ntype(x) != CONS)
  2325. X#define null(x)        ((x) == NIL)
  2326. X#define listp(x)    ((x) == NIL || ntype(x) == CONS)
  2327. X#define consp(x)    ((x) && ntype(x) == CONS)
  2328. X#define subrp(x)    ((x) && ntype(x) == SUBR)
  2329. X#define fsubrp(x)    ((x) && ntype(x) == FSUBR)
  2330. X#define stringp(x)    ((x) && ntype(x) == STRING)
  2331. X#define symbolp(x)    ((x) && ntype(x) == SYMBOL)
  2332. X#define streamp(x)    ((x) && ntype(x) == STREAM)
  2333. X#define objectp(x)    ((x) && ntype(x) == OBJECT)
  2334. X#define fixp(x)        ((x) && ntype(x) == FIXNUM)
  2335. X#define floatp(x)    ((x) && ntype(x) == FLONUM)
  2336. X#define vectorp(x)    ((x) && ntype(x) == VECTOR)
  2337. X#define closurep(x)    ((x) && ntype(x) == CLOSURE)
  2338. X#define charp(x)    ((x) && ntype(x) == CHAR)
  2339. X#define ustreamp(x)    ((x) && ntype(x) == USTREAM)
  2340. X#define structp(x)    ((x) && ntype(x) == STRUCT)
  2341. X#define boundp(x)    (getvalue(x) != s_unbound)
  2342. X#define fboundp(x)    (getfunction(x) != s_unbound)
  2343. X
  2344. X/* shorthand functions */
  2345. X#define consa(x)    cons(x,NIL)
  2346. X#define consd(x)    cons(NIL,x)
  2347. X
  2348. X/* argument list parsing macros */
  2349. X#define xlgetarg()    (testarg(nextarg()))
  2350. X#define xllastarg()    {if (xlargc != 0) xltoomany();}
  2351. X#define testarg(e)    (moreargs() ? (e) : xltoofew())
  2352. X#define typearg(tp)    (tp(*xlargv) ? nextarg() : xlbadtype(*xlargv))
  2353. X#define nextarg()    (--xlargc, *xlargv++)
  2354. X#define moreargs()    (xlargc > 0)
  2355. X
  2356. X/* macros to get arguments of a particular type */
  2357. X#define xlgacons()    (testarg(typearg(consp)))
  2358. X#define xlgalist()    (testarg(typearg(listp)))
  2359. X#define xlgasymbol()    (testarg(typearg(symbolp)))
  2360. X#define xlgastring()    (testarg(typearg(stringp)))
  2361. X#define xlgaobject()    (testarg(typearg(objectp)))
  2362. X#define xlgafixnum()    (testarg(typearg(fixp)))
  2363. X#define xlgaflonum()    (testarg(typearg(floatp)))
  2364. X#define xlgachar()    (testarg(typearg(charp)))
  2365. X#define xlgavector()    (testarg(typearg(vectorp)))
  2366. X#define xlgastream()    (testarg(typearg(streamp)))
  2367. X#define xlgaustream()    (testarg(typearg(ustreamp)))
  2368. X#define xlgaclosure()    (testarg(typearg(closurep)))
  2369. X#define xlgastruct()    (testarg(typearg(structp)))
  2370. X
  2371. X/* function definition structure */
  2372. Xtypedef struct {
  2373. X    char *fd_name;    /* function name */
  2374. X    int fd_type;    /* function type */
  2375. X    LVAL (*fd_subr)();    /* function entry point */
  2376. X} FUNDEF;
  2377. X
  2378. X/* execution context flags */
  2379. X#define CF_GO        0x0001
  2380. X#define CF_RETURN    0x0002
  2381. X#define CF_THROW    0x0004
  2382. X#define CF_ERROR    0x0008
  2383. X#define CF_CLEANUP    0x0010
  2384. X#define CF_CONTINUE    0x0020
  2385. X#define CF_TOPLEVEL    0x0040
  2386. X#define CF_BRKLEVEL    0x0080
  2387. X#define CF_UNWIND    0x0100
  2388. X
  2389. X/* execution context */
  2390. Xtypedef struct context {
  2391. X    int c_flags;            /* context type flags */
  2392. X    LVAL c_expr;            /* expression (type dependant) */
  2393. X    jmp_buf c_jmpbuf;            /* longjmp context */
  2394. X    struct context *c_xlcontext;    /* old value of xlcontext */
  2395. X    LVAL **c_xlstack;            /* old value of xlstack */
  2396. X    LVAL *c_xlargv;            /* old value of xlargv */
  2397. X    int c_xlargc;            /* old value of xlargc */
  2398. X    LVAL *c_xlfp;            /* old value of xlfp */
  2399. X    LVAL *c_xlsp;            /* old value of xlsp */
  2400. X    LVAL c_xlenv;            /* old value of xlenv */
  2401. X    LVAL c_xlfenv;            /* old value of xlfenv */
  2402. X    LVAL c_xldenv;            /* old value of xldenv */
  2403. X} CONTEXT;
  2404. X
  2405. X/* external variables */
  2406. Xextern LVAL **xlstktop;           /* top of the evaluation stack */
  2407. Xextern LVAL **xlstkbase;    /* base of the evaluation stack */
  2408. Xextern LVAL **xlstack;        /* evaluation stack pointer */
  2409. Xextern LVAL *xlargstkbase;    /* base of the argument stack */
  2410. Xextern LVAL *xlargstktop;    /* top of the argument stack */
  2411. Xextern LVAL *xlfp;        /* argument frame pointer */
  2412. Xextern LVAL *xlsp;        /* argument stack pointer */
  2413. Xextern LVAL *xlargv;        /* current argument vector */
  2414. Xextern int xlargc;        /* current argument count */
  2415. X
  2416. X/* external procedure declarations */
  2417. Xextern LVAL xleval();        /* evaluate an expression */
  2418. Xextern LVAL xlapply();        /* apply a function to arguments */
  2419. Xextern LVAL xlsubr();        /* enter a subr/fsubr */
  2420. Xextern LVAL xlenter();        /* enter a symbol */
  2421. Xextern LVAL xlmakesym();    /* make an uninterned symbol */
  2422. Xextern LVAL xlgetvalue();    /* get value of a symbol (checked) */
  2423. Xextern LVAL xlxgetvalue();    /* get value of a symbol */
  2424. Xextern LVAL xlgetfunction();    /* get functional value of a symbol */
  2425. Xextern LVAL xlxgetfunction();    /* get functional value of a symbol (checked) */
  2426. Xextern LVAL xlexpandmacros();    /* expand macros in a form */
  2427. Xextern LVAL xlgetprop();    /* get the value of a property */
  2428. Xextern LVAL xlclose();        /* create a function closure */
  2429. X
  2430. X/* argument list parsing functions */
  2431. Xextern LVAL xlgetfile();          /* get a file/stream argument */
  2432. Xextern LVAL xlgetfname();    /* get a filename argument */
  2433. X
  2434. X/* error reporting functions (don't *really* return at all) */
  2435. Xextern LVAL xltoofew();        /* report "too few arguments" error */
  2436. Xextern LVAL xlbadtype();    /* report "bad argument type" error */
  2437. X
  2438. SHAR_EOF
  2439. if test 9630 -ne "`wc -c 'xlisp.h'`"
  2440. then
  2441.     echo shar: error transmitting "'xlisp.h'" '(should have been 9630 characters)'
  2442. fi
  2443. echo shar: extracting "'xlisp.lnk'" '(267 characters)'
  2444. if test -f 'xlisp.lnk'
  2445. then
  2446.     echo shar: over-writing existing file "'xlisp.lnk'"
  2447. fi
  2448. sed 's/^X//' << \SHAR_EOF > 'xlisp.lnk'
  2449. Xc:\turboc\lib\c0l.obj +
  2450. Xxlisp xlbfun xlcont xldbug xldmem xleval xlfio +
  2451. Xxlftab xlglob xlimage xlinit xlio xljump xllist    +
  2452. Xxlmath xlobj xlpp xlprin xlread xlstr xlstruct +
  2453. Xxlsubr xlsym xlsys msstuff
  2454. Xxlisp
  2455. Xxlisp
  2456. Xc:\turboc\lib\emu c:\turboc\lib\mathl c:\turboc\lib\cl
  2457. X
  2458. SHAR_EOF
  2459. if test 267 -ne "`wc -c 'xlisp.lnk'`"
  2460. then
  2461.     echo shar: error transmitting "'xlisp.lnk'" '(should have been 267 characters)'
  2462. fi
  2463. echo shar: extracting "'xlisp.mac'" '(27375 characters)'
  2464. if test -f 'xlisp.mac'
  2465. then
  2466.     echo shar: over-writing existing file "'xlisp.mac'"
  2467. fi
  2468. sed 's/^X//' << \SHAR_EOF > 'xlisp.mac'
  2469. XFrom sce!mitel!uunet!datapg!com50!pai!erc Tue Nov 14 08:51:33 EST 1989
  2470. XArticle: 753 of comp.lang.scheme
  2471. XPath: cognos!sce!mitel!uunet!datapg!com50!pai!erc
  2472. XFrom: erc@pai.UUCP (Eric Johnson)
  2473. XNewsgroups: comp.lang.scheme,comp.sys.mac
  2474. XSubject: Re: How to build xscheme for the mac
  2475. XSummary: Hope this helps...
  2476. XKeywords: xscheme, mac
  2477. XMessage-ID: <742@pai.UUCP>
  2478. XDate: 11 Nov 89 18:55:05 GMT
  2479. XReferences: <2091@cunixc.cc.columbia.edu>
  2480. XOrganization: Prime Automation, Inc., Burnsville, MN
  2481. XLines: 1374
  2482. XXref: cognos comp.lang.scheme:753 comp.sys.mac:33459
  2483. X
  2484. XIn article <2091@cunixc.cc.columbia.edu>, puglia@cunixc.cc.columbia.edu (Paul Puglia) writes:
  2485. X> How does you build xscheme on a macintosh ? I have a copy of 
  2486. X> the xscheme sources compiles fine on a unix machine, and works
  2487. X> great on a pc with turbo c.  When I tried to compile it on a 
  2488. X> friends mac II using his copy of lightspeed c. I have no luck. 
  2489. X> Could someone please describe the procedure to compile this program, and
  2490. X> comment on if anything else is need to compile xscheme. I know that you 
  2491. X> need some resource to compile xlisp on a mac. Do you need the same sort of 
  2492. X> stuff for xscheme
  2493. X> Thanks in advance
  2494. X> Paul Puglia
  2495. X> Dept of Civil Engineering 
  2496. X> Columbia University
  2497. X
  2498. X
  2499. X
  2500. XPorting Xlisp/XScheme:
  2501. X
  2502. XAwhile back, while I was taking an AI course, I was spending a lot of time
  2503. Xtrekking to campus and using their LISP system.  To avoid travel time (and
  2504. Xto work on LISP at any hour I wanted), I got into porting XLisp. In looking at 
  2505. Xthe code, I'd say XLisp and XScheme are two of the most portable C programs
  2506. XI have ever seen.  Now, I've spent most of my time on XLisp, so your
  2507. Xmileage may vary, but...
  2508. X
  2509. XXLisp seems to place most Operating System (OS)-dependent features in 
  2510. Xseparate files, named dosstuff.c, osptrs.h, osdefs.h.  On UNIX, the "stuff:
  2511. Xfile is called unixstuf.c and on the Mac its called macstuff.c (all file
  2512. Xnames are <= 8 chars for MS-DOS).  The mac version also has a resource
  2513. Xcompiler file (that is, a file you run through the resource compiler to
  2514. Xgenerate a resource file).
  2515. X
  2516. XI assume (hope) XScheme is similiar.  Below, I placed all my Mac-related
  2517. Xfiles from XLisp (2.0, I think).  The XScheme stuff should be similiar.
  2518. XI hope these help.  (Note: I don't have the full sources around now, just
  2519. Xthe Mac and UNIX-specific files.)  (Note2: Two extra files, macfun.c and
  2520. Xmacinit.c are below, its been so long that I'm not sure if these are extras
  2521. Xor necessary--Sorry.)
  2522. X
  2523. XI'm placing these files here in hopes they can help you with your porting.  I
  2524. Xdo know that binary executable versions of XScheme are available on the
  2525. XBIX bulletin board (Byte magazine Information eXchange)--see Byte mag
  2526. Xfor details.  Getting the binaries would solve all the Mac porting
  2527. Xproblems in one fell swoop.
  2528. X
  2529. XAnyway, hope this helps,
  2530. X-Eric
  2531. X
  2532. X
  2533. X======================== macfun.c =============================================
  2534. X
  2535. X/* macfun.c - macintosh user interface functions for xlisp */
  2536. X
  2537. X#include <Quickdraw.h>
  2538. X#include <WindowMgr.h>
  2539. X#include <MemoryMgr.h>
  2540. X#include "xlisp.h"
  2541. X
  2542. X/* external variables */
  2543. Xextern GrafPtr cwindow,gwindow;
  2544. X
  2545. X/* forward declarations */
  2546. XFORWARD LVAL do_0();
  2547. XFORWARD LVAL do_1();
  2548. XFORWARD LVAL do_2();
  2549. X
  2550. X/* xptsize - set the command window point size */
  2551. XLVAL xptsize()
  2552. X{
  2553. X    LVAL val;
  2554. X    val = xlgafixnum();
  2555. X    xllastarg();
  2556. X    TextSize((int)getfixnum(val));
  2557. X    InvalRect(&cwindow->portRect);
  2558. X    SetupScreen();
  2559. X    return (NIL);
  2560. X}
  2561. X
  2562. X/* xhidepen - hide the pen */
  2563. XLVAL xhidepen()
  2564. X{
  2565. X    return (do_0('H'));
  2566. X}
  2567. X
  2568. X/* xshowpen - show the pen */
  2569. XLVAL xshowpen()
  2570. X{
  2571. X    return (do_0('S'));
  2572. X}
  2573. X
  2574. X/* xgetpen - get the pen position */
  2575. XLVAL xgetpen()
  2576. X{
  2577. X    LVAL val;
  2578. X    Point p;
  2579. X    xllastarg();
  2580. X    SetPort(gwindow);
  2581. X    GetPen(&p);
  2582. X    SetPort(cwindow);
  2583. X    xlsave1(val);
  2584. X    val = consa(NIL);
  2585. X    rplaca(val,cvfixnum((FIXTYPE)p.h));
  2586. X    rplacd(val,cvfixnum((FIXTYPE)p.v));
  2587. X    xlpop();
  2588. X    return (val);
  2589. X}
  2590. X
  2591. X/* xpenmode - set the pen mode */
  2592. XLVAL xpenmode()
  2593. X{
  2594. X    return (do_1('M'));
  2595. X}
  2596. X
  2597. X/* xpensize - set the pen size */
  2598. XLVAL xpensize()
  2599. X{
  2600. X    return (do_2('S'));
  2601. X}
  2602. X
  2603. X/* xpenpat - set the pen pattern */
  2604. XLVAL xpenpat()
  2605. X{
  2606. X    LVAL plist;
  2607. X    char pat[8],i;
  2608. X    plist = xlgalist();
  2609. X    xllastarg();
  2610. X    for (i = 0; i < 8 && consp(plist); ++i, plist = cdr(plist))
  2611. X    if (fixp(car(plist)))
  2612. X        pat[i] = getfixnum(car(plist));
  2613. X    SetPort(gwindow);
  2614. X    PenPat(pat);
  2615. X    SetPort(cwindow);
  2616. X    return (NIL);
  2617. X}
  2618. X
  2619. X/* xpennormal - set the pen to normal */
  2620. XLVAL xpennormal()
  2621. X{
  2622. X    xllastarg();
  2623. X    SetPort(gwindow);
  2624. X    PenNormal();
  2625. X    SetPort(cwindow);
  2626. X    return (NIL);
  2627. X}
  2628. X
  2629. X/* xmoveto - Move to a screen location */
  2630. XLVAL xmoveto()
  2631. X{
  2632. X    return (do_2('m'));
  2633. X}
  2634. X
  2635. X/* xmove - Move in a specified direction */
  2636. XLVAL xmove()
  2637. X{
  2638. X    return (do_2('M'));
  2639. X}
  2640. X
  2641. X/* xlineto - draw a Line to a screen location */
  2642. XLVAL xlineto()
  2643. X{
  2644. X    return (do_2('l'));
  2645. X}
  2646. X
  2647. X/* xline - draw a Line in a specified direction */
  2648. XLVAL xline()
  2649. X{
  2650. X    return (do_2('L'));
  2651. X}
  2652. X
  2653. X/* xshowgraphics - show the graphics window */
  2654. XLVAL xshowgraphics()
  2655. X{
  2656. X    xllastarg();
  2657. X    scrsplit(1);
  2658. X    return (NIL);
  2659. X}
  2660. X
  2661. X/* xhidegraphics - hide the graphics window */
  2662. XLVAL xhidegraphics()
  2663. X{
  2664. X    xllastarg();
  2665. X    scrsplit(0);
  2666. X    return (NIL);
  2667. X}
  2668. X
  2669. X/* xcleargraphics - clear the graphics window */
  2670. XLVAL xcleargraphics()
  2671. X{
  2672. X    xllastarg();
  2673. X    SetPort(gwindow);
  2674. X    EraseRect(&gwindow->portRect);
  2675. X    SetPort(cwindow);
  2676. X    return (NIL);
  2677. X}
  2678. X
  2679. X/* do_0 - Handle commands that require no arguments */
  2680. XLOCAL LVAL do_0(fcn)
  2681. X  int fcn;
  2682. X{
  2683. X    xllastarg();
  2684. X    SetPort(gwindow);
  2685. X    switch (fcn) {
  2686. X    case 'H':    HidePen(); break;
  2687. X    case 'S':    ShowPen(); break;
  2688. X    }
  2689. X    SetPort(cwindow);
  2690. X    return (NIL);
  2691. X}
  2692. X
  2693. X/* do_1 - Handle commands that require one integer argument */
  2694. XLOCAL LVAL do_1(fcn)
  2695. X  int fcn;
  2696. X{
  2697. X    int x;
  2698. X    x = getnumber();
  2699. X    xllastarg();
  2700. X    SetPort(gwindow);
  2701. X    switch (fcn) {
  2702. X    case 'M':    PenMode(x); break;
  2703. X    }
  2704. X    SetPort(cwindow);
  2705. X    return (NIL);
  2706. X}
  2707. X
  2708. X/* do_2 - Handle commands that require two integer arguments */
  2709. XLOCAL LVAL do_2(fcn)
  2710. X  int fcn;
  2711. X{
  2712. X    int h,v;
  2713. X    h = getnumber();
  2714. X    v = getnumber();
  2715. X    xllastarg();
  2716. X    SetPort(gwindow);
  2717. X    switch (fcn) {
  2718. X    case 'l':    LineTo(h,v); break;
  2719. X    case 'L':    Line(h,v);   break;
  2720. X    case 'm':   MoveTo(h,v); break;
  2721. X    case 'M':    Move(h,v);   break;
  2722. X    case 'S':    PenSize(h,v);break;
  2723. X    }
  2724. X    SetPort(cwindow);
  2725. X    return (NIL);
  2726. X}
  2727. X
  2728. X/* getnumber - get an integer parameter */
  2729. XLOCAL int getnumber()
  2730. X{
  2731. X    LVAL num;
  2732. X    num = xlgafixnum();
  2733. X    return ((int)getfixnum(num));
  2734. X}
  2735. X
  2736. X/* xtool - call the toolbox */
  2737. XLVAL xtool()
  2738. X{
  2739. X    LVAL val;
  2740. X    int trap;
  2741. X
  2742. X    trap = getnumber();
  2743. X/*
  2744. X
  2745. X    asm {
  2746. X    move.l    args(A6),D0
  2747. X    beq    L2
  2748. XL1:    move.l    D0,A0
  2749. X    move.l    2(A0),A1
  2750. X    move.w    4(A1),-(A7)
  2751. X    move.l    6(A0),D0
  2752. X    bne    L1
  2753. XL2:    lea    L3,A0
  2754. X    move.w    trap(A6),(A0)
  2755. XL3:    dc.w    0xA000
  2756. X    clr.l    val(A6)
  2757. X    }
  2758. X*/
  2759. X
  2760. X    return (val);
  2761. X}
  2762. X
  2763. X/* xtool16 - call the toolbox with a 16 bit result */
  2764. XLVAL xtool16()
  2765. X{
  2766. X    int trap,val;
  2767. X
  2768. X    trap = getnumber();
  2769. X/*
  2770. X
  2771. X    asm {
  2772. X    clr.w    -(A7)
  2773. X    move.l    args(A6),D0
  2774. X    beq    L2
  2775. XL1:    move.l    D0,A0
  2776. X    move.l    2(A0),A1
  2777. X    move.w    4(A1),-(A7)
  2778. X    move.l    6(A0),D0
  2779. X    bne    L1
  2780. XL2:    lea    L3,A0
  2781. X    move.w    trap(A6),(A0)
  2782. XL3:    dc.w    0xA000
  2783. X    move.w    (A7)+,val(A6)
  2784. X    }
  2785. X*/
  2786. X
  2787. X    return (cvfixnum((FIXTYPE)val));
  2788. X}
  2789. X
  2790. X/* xtool32 - call the toolbox with a 32 bit result */
  2791. XLVAL xtool32()
  2792. X{
  2793. X    int trap;
  2794. X    long val;
  2795. X
  2796. X    trap = getnumber();
  2797. X/*
  2798. X
  2799. X    asm {
  2800. X    clr.l    -(A7)
  2801. X    move.l    args(A6),D0
  2802. X    beq    L2
  2803. XL1:    move.l    D0,A0
  2804. X    move.l    2(A0),A1
  2805. X    move.w    4(A1),-(A7)
  2806. X    move.l    6(A0),D0
  2807. X    bne    L1
  2808. XL2:    lea    L3,A0
  2809. X    move.w    trap(A6),(A0)
  2810. XL3:    dc.w    0xA000
  2811. X    move.l    (A7)+,val(A6)
  2812. X    }
  2813. X*/
  2814. X
  2815. X    return (cvfixnum((FIXTYPE)val));
  2816. X}
  2817. X
  2818. X/* xnewhandle - allocate a new handle */
  2819. XLVAL xnewhandle()
  2820. X{
  2821. X    LVAL num;
  2822. X    long size;
  2823. X    num = xlgafixnum(); size = getfixnum(num);
  2824. X    xllastarg();
  2825. X    return (cvfixnum((FIXTYPE)NewHandle(size)));
  2826. X}
  2827. X
  2828. X/* xnewptr - allocate memory */
  2829. XLVAL xnewptr()
  2830. X{
  2831. X    LVAL num;
  2832. X    long size;
  2833. X    num = xlgafixnum(); size = getfixnum(num);
  2834. X    xllastarg();
  2835. X    return (cvfixnum((FIXTYPE)NewPtr(size)));
  2836. X}
  2837. X    
  2838. X/* xhiword - return the high order 16 bits of an integer */
  2839. XLVAL xhiword()
  2840. X{
  2841. X    unsigned int val;
  2842. X    val = (unsigned int)(getnumber() >> 16);
  2843. X    xllastarg();
  2844. X    return (cvfixnum((FIXTYPE)val));
  2845. X}
  2846. X
  2847. X/* xloword - return the low order 16 bits of an integer */
  2848. XLVAL xloword()
  2849. X{
  2850. X    unsigned int val;
  2851. X    val = (unsigned int)getnumber();
  2852. X    xllastarg();
  2853. X    return (cvfixnum((FIXTYPE)val));
  2854. X}
  2855. X
  2856. X/* xrdnohang - get the next character in the look-ahead buffer */
  2857. XLVAL xrdnohang()
  2858. X{
  2859. X    int ch;
  2860. X    xllastarg();
  2861. X    if ((ch = scrnextc()) == EOF)
  2862. X    return (NIL);
  2863. X    return (cvfixnum((FIXTYPE)ch));
  2864. X}
  2865. X
  2866. X/* ossymbols - enter important symbols */
  2867. Xossymbols()
  2868. X{
  2869. X    LVAL sym;
  2870. X
  2871. X    /* setup globals for the window handles */
  2872. X    sym = xlenter("*COMMAND-WINDOW*");
  2873. X    setvalue(sym,cvfixnum((FIXTYPE)cwindow));
  2874. X    sym = xlenter("*GRAPHICS-WINDOW*");
  2875. X    setvalue(sym,cvfixnum((FIXTYPE)gwindow));
  2876. X}
  2877. X
  2878. X
  2879. X======================== macint.c =============================================
  2880. X
  2881. X/* macint.c - macintosh interface routines for xlisp */
  2882. X
  2883. X#include <MacTypes.h>
  2884. X#include <Quickdraw.h>  
  2885. X#include <WindowMgr.h>
  2886. X#include <EventMgr.h>
  2887. X#include <DialogMgr.h>
  2888. X#include <MenuMgr.h>
  2889. X#include <PackageMgr.h>
  2890. X#include <StdFilePkg.h>
  2891. X#include <MemoryMgr.h>
  2892. X#include <DeskMgr.h>
  2893. X#include <FontMgr.h>
  2894. X#include <ControlMgr.h>
  2895. X#include <SegmentLdr.h>
  2896. X#include <FileMgr.h>
  2897. X
  2898. X/* program limits */
  2899. X#define SCRH        40    /* maximum screen height */
  2900. X#define SCRW        100    /* maximum screen width */
  2901. X#define CHARMAX     100    /* maximum number of buffered characters */
  2902. X#define TIMEON        40    /* cursor on time */
  2903. X#define TIMEOFF        20    /* cursor off time */
  2904. X
  2905. X/* useful definitions */
  2906. X#define MenuBarHeight    20
  2907. X#define TitleBarHeight    20
  2908. X#define SBarWidth    16
  2909. X#define MinWidth    80
  2910. X#define MinHeight    40
  2911. X#define ScreenMargin    2
  2912. X#define TextMargin    4
  2913. X#define GHeight        232
  2914. X
  2915. X/* menu id's */
  2916. X#define appleID        1
  2917. X#define fileID        256
  2918. X#define editID        257
  2919. X#define controlID    258
  2920. X
  2921. X/* externals */
  2922. Xextern char *s_unbound;
  2923. Xextern char *PtoCstr();
  2924. X
  2925. X/* screen dimensions */
  2926. Xint screenWidth;
  2927. Xint screenHeight;
  2928. X
  2929. X/* command window (normal screen) */
  2930. Xint nHorizontal,nVertical,nWidth,nHeight;
  2931. X
  2932. X/* command window (split screen) */
  2933. Xint sHorizontal,sVertical,sWidth,sHeight;
  2934. X
  2935. X/* graphics window */
  2936. Xint gHorizontal,gVertical,gWidth,gHeight;
  2937. X
  2938. X/* menu handles */
  2939. XMenuHandle appleMenu;
  2940. XMenuHandle fileMenu;
  2941. XMenuHandle editMenu;
  2942. XMenuHandle controlMenu;
  2943. X
  2944. X/* misc variables */
  2945. XOSType filetypes[] = { 'TEXT' };
  2946. X
  2947. X/* font information */
  2948. Xint tmargin,lmargin;
  2949. Xint xinc,yinc;
  2950. X
  2951. X/* command window */
  2952. XWindowRecord cwrecord;
  2953. XWindowPtr cwindow;
  2954. X
  2955. X/* graphics window */
  2956. XWindowRecord gwrecord;
  2957. XWindowPtr gwindow;
  2958. X
  2959. X/* window mode */
  2960. Xint splitmode;
  2961. X
  2962. X/* cursor variables */
  2963. Xlong cursortime;
  2964. Xint cursorstate;
  2965. Xint x,y;
  2966. X
  2967. X/* screen buffer */
  2968. Xchar screen[SCRH*SCRW],*topline,*curline;
  2969. Xint scrh,scrw;
  2970. X
  2971. X/* type ahead buffer */
  2972. Xchar charbuf[CHARMAX],*inptr,*outptr;
  2973. Xint charcnt;
  2974. X
  2975. Xmacinit()
  2976. X{
  2977. X    /* initialize the toolbox */
  2978. X    InitGraf(&thePort);
  2979. X    InitFonts();
  2980. X    InitWindows();
  2981. X    InitMenus();
  2982. X    TEInit();
  2983. X    InitDialogs(0L);
  2984. X    InitCursor();
  2985. X
  2986. X    /* setup the menu bar */
  2987. X    SetupMenus();
  2988. X
  2989. X    /* get the size of the screen */
  2990. X    screenWidth  = screenBits.bounds.right  - screenBits.bounds.left;
  2991. X    screenHeight = screenBits.bounds.bottom - screenBits.bounds.top;
  2992. X
  2993. X    /* Create the graphics and control windows */
  2994. X    gwindow = GetNewWindow(129,&gwrecord,-1L);
  2995. X    cwindow = GetNewWindow(128,&cwrecord,-1L);
  2996. X
  2997. X    /* establish the command window as the current port */
  2998. X    SetPort(cwindow);
  2999. X
  3000. X    /* compute the size of the normal command window */
  3001. X    nHorizontal = ScreenMargin;
  3002. X    nVertical = MenuBarHeight + TitleBarHeight + ScreenMargin - 2;
  3003. X    nWidth = screenWidth - (ScreenMargin * 2) - 1;
  3004. X    nHeight = screenHeight - MenuBarHeight - TitleBarHeight - (ScreenMargin * 2);
  3005. X
  3006. X    /* compute the size of the split command window */
  3007. X    sHorizontal = nHorizontal;
  3008. X    sVertical = nVertical + GHeight + 1;
  3009. X    sWidth = nWidth;
  3010. X    sHeight = nHeight - GHeight - 1;
  3011. X
  3012. X    /* compute the size of the graphics window */
  3013. X    gHorizontal = nHorizontal;
  3014. X    gVertical = MenuBarHeight + ScreenMargin;
  3015. X    gWidth = screenWidth - (ScreenMargin * 2);
  3016. X    gHeight = GHeight;
  3017. X
  3018. X    /* move and size the graphics window */
  3019. X    MoveWindow(gwindow,gHorizontal,gVertical,0);
  3020. X    SizeWindow(gwindow,gWidth,gHeight,0);
  3021. X
  3022. X    /* setup the font, size and writing mode for the command window */
  3023. X    TextFont(monaco); TextSize(9); TextMode(srcCopy);
  3024. X
  3025. X    /* setup command mode */
  3026. X    scrsplit(FALSE);
  3027. X
  3028. X    /* disable the Cursor */
  3029. X    cursorstate = -1;
  3030. X
  3031. X    /* setup the input ring buffer */
  3032. X    inptr = outptr = charbuf;
  3033. X    charcnt = 0;
  3034. X    
  3035. X    /* lock the font in memory */
  3036. X    SetFontLock(-1);
  3037. X}
  3038. X
  3039. XSetupMenus()
  3040. X{
  3041. X    appleMenu = GetMenu(appleID);    /* setup the apple menu */
  3042. X    AddResMenu(appleMenu,'DRVR');
  3043. X    InsertMenu(appleMenu,0);
  3044. X    fileMenu = GetMenu(fileID);        /* setup the file menu */
  3045. X    InsertMenu(fileMenu,0);
  3046. X    editMenu = GetMenu(editID);        /* setup the edit menu */
  3047. X    InsertMenu(editMenu,0);
  3048. X    controlMenu = GetMenu(controlID);    /* setup the control menu */
  3049. X    InsertMenu(controlMenu,0);
  3050. X    DrawMenuBar();
  3051. X}
  3052. X
  3053. Xint scrgetc()
  3054. X{
  3055. X    CursorOn();
  3056. X    while (charcnt == 0)
  3057. X    DoEvent();
  3058. X    CursorOff();
  3059. X    return (scrnextc());
  3060. X}
  3061. X
  3062. Xint scrnextc()
  3063. X{
  3064. X    int ch;
  3065. X    if (charcnt > 0) {
  3066. X    ch = *outptr++; charcnt--;
  3067. X    if (outptr >= &charbuf[CHARMAX])
  3068. X        outptr = charbuf;
  3069. X    }
  3070. X    else {
  3071. X    charcnt = 0;
  3072. X    ch = -1;
  3073. X    }
  3074. X    return (ch);
  3075. X}
  3076. X
  3077. Xscrputc(ch)
  3078. X  int ch;
  3079. X{
  3080. X    switch (ch) {
  3081. X    case '\r':
  3082. X    x = 0;
  3083. X    break;
  3084. X    case '\n':
  3085. X    nextline(&curline);
  3086. X    if (++y >= scrh) {
  3087. X        y = scrh - 1;
  3088. X        scrollup();
  3089. X    }
  3090. X    break;
  3091. X    case '\t':
  3092. X    do { scrputc(' '); } while (x & 7);
  3093. X    break;
  3094. X    case '\010':
  3095. X    if (x) x--;
  3096. X    break;
  3097. X    default:
  3098. X    if (ch >= 0x20 && ch < 0x7F) {
  3099. X        scrposition(x,y);
  3100. X        DrawChar(ch);
  3101. X        curline[x] = ch;
  3102. X        if (++x >= scrw) {
  3103. X        nextline(&curline);
  3104. X        if (++y >= scrh) {
  3105. X            y = scrh - 1;
  3106. X            scrollup();
  3107. X        }
  3108. X        x = 0;
  3109. X        }
  3110. X    }
  3111. X    break;
  3112. X    }
  3113. X}
  3114. X
  3115. Xscrdelete()
  3116. X{
  3117. X    scrputc('\010');
  3118. X    scrputc(' ');
  3119. X    scrputc('\010');
  3120. X}
  3121. X
  3122. Xscrclear()
  3123. X{
  3124. X    curline = screen;
  3125. X    for (y = 0; y < SCRH; y++)
  3126. X    for (x = 0; x < SCRW; x++)
  3127. X        *curline++ = ' ';
  3128. X    topline = curline = screen;
  3129. X    x = y = 0;
  3130. X}
  3131. X
  3132. Xscrflush()
  3133. X{
  3134. X    inptr = outptr = charbuf;
  3135. X    charcnt = -1;
  3136. X    osflush();
  3137. X}
  3138. X
  3139. Xscrposition(x,y)
  3140. X  int x,y;
  3141. X{
  3142. X    MoveTo((x * xinc) + lmargin,(y * yinc) + tmargin);
  3143. X}
  3144. X
  3145. XDoEvent()
  3146. X{
  3147. X    EventRecord myEvent;
  3148. X    
  3149. X    SystemTask();
  3150. X    CursorUpdate();
  3151. X
  3152. X    while (GetNextEvent(everyEvent,&myEvent))
  3153. X    switch (myEvent.what) {
  3154. X        case mouseDown:
  3155. X        DoMouseDown(&myEvent);
  3156. X        break;
  3157. X        case keyDown:
  3158. X        case autoKey:
  3159. X        DoKeyPress(&myEvent);
  3160. X        break;
  3161. X        case activateEvt:
  3162. X        DoActivate(&myEvent);
  3163. X        break;
  3164. X        case updateEvt:
  3165. X        DoUpdate(&myEvent);
  3166. X        break;
  3167. X        }
  3168. X}
  3169. X
  3170. XDoMouseDown(myEvent)
  3171. X  EventRecord *myEvent;
  3172. X{
  3173. X    WindowPtr whichWindow;
  3174. X
  3175. X    switch (FindWindow(myEvent->where,&whichWindow)) {
  3176. X    case inMenuBar:
  3177. X    DoMenuClick(myEvent);
  3178. X    break;
  3179. X    case inSysWindow:
  3180. X    SystemClick(myEvent,whichWindow);
  3181. X    break;
  3182. X    case inDrag:
  3183. X    DoDrag(myEvent,whichWindow);
  3184. X    break;
  3185. X    case inGoAway:
  3186. X    DoGoAway(myEvent,whichWindow);
  3187. X    break;
  3188. X    case inGrow:
  3189. X    DoGrow(myEvent,whichWindow);
  3190. X    break;
  3191. X    case inContent:
  3192. X    DoContent(myEvent,whichWindow);
  3193. X    break;
  3194. X    }
  3195. X}
  3196. X
  3197. XDoMenuClick(myEvent)
  3198. X  EventRecord *myEvent;
  3199. X{
  3200. X    long choice;
  3201. X    if (choice = MenuSelect(myEvent->where))
  3202. X    DoCommand(choice);
  3203. X}
  3204. X
  3205. XDoDrag(myEvent,whichWindow)
  3206. X  EventRecord *myEvent;
  3207. X  WindowPtr whichWindow;
  3208. X{
  3209. X    Rect dragRect;
  3210. X    SetRect(&dragRect,0,MenuBarHeight,screenWidth,screenHeight);
  3211. X    InsetRect(&dragRect,ScreenMargin,ScreenMargin);
  3212. X    DragWindow(whichWindow,myEvent->where,&dragRect);
  3213. X}
  3214. X
  3215. XDoGoAway(myEvent,whichWindow)
  3216. X  EventRecord *myEvent;
  3217. X  WindowPtr whichWindow;
  3218. X{
  3219. X    if (TrackGoAway(whichWindow,myEvent->where))
  3220. X    wrapup();
  3221. X}
  3222. X
  3223. XDoGrow(myEvent,whichWindow)
  3224. X  EventRecord *myEvent;
  3225. X  WindowPtr whichWindow;
  3226. X{
  3227. X    Rect sizeRect;
  3228. X    long newSize;
  3229. X    if (whichWindow != FrontWindow() && whichWindow != gwindow)
  3230. X    SelectWindow(whichWindow);
  3231. X    else {
  3232. X    SetRect(&sizeRect,MinWidth,MinHeight,screenWidth,screenHeight-MenuBarHeight);
  3233. X    newSize = GrowWindow(whichWindow,myEvent->where,&sizeRect);
  3234. X    if (newSize) {
  3235. X        EraseRect(&whichWindow->portRect);
  3236. X        SizeWindow(whichWindow,LoWord(newSize),HiWord(newSize),-1);
  3237. X        InvalRect(&whichWindow->portRect);
  3238. X        SetupScreen();
  3239. X        scrflush();
  3240. X    }
  3241. X    }
  3242. X}
  3243. X
  3244. XDoContent(myEvent,whichWindow)
  3245. X  EventRecord *myEvent;
  3246. X  WindowPtr whichWindow;
  3247. X{
  3248. X    if (whichWindow != FrontWindow() && whichWindow != gwindow)
  3249. X    SelectWindow(whichWindow);
  3250. X}
  3251. X
  3252. XDoKeyPress(myEvent)
  3253. X  EventRecord *myEvent;
  3254. X{
  3255. X    long choice;
  3256. X    
  3257. X    if (FrontWindow() == cwindow) {
  3258. X    if (myEvent->modifiers & 0x100) {
  3259. X        if (choice = MenuKey((char)myEvent->message))
  3260. X        DoCommand(choice);
  3261. X    }
  3262. X    else {
  3263. X        if (charcnt < CHARMAX) {
  3264. X        *inptr++ = myEvent->message & 0xFF; charcnt++;
  3265. X        if (inptr >= &charbuf[CHARMAX])
  3266. X            inptr = charbuf;
  3267. X        }
  3268. X    }
  3269. X    }
  3270. X}
  3271. X
  3272. XDoActivate(myEvent)
  3273. X  EventRecord *myEvent;
  3274. X{
  3275. X    WindowPtr whichWindow;
  3276. X    whichWindow = (WindowPtr)myEvent->message;
  3277. X    SetPort(whichWindow);
  3278. X    if (whichWindow == cwindow)
  3279. X    DrawGrowIcon(whichWindow);
  3280. X}
  3281. X
  3282. XDoUpdate(myEvent)
  3283. X  EventRecord *myEvent;
  3284. X{
  3285. X    WindowPtr whichWindow;
  3286. X    GrafPtr savePort;
  3287. X    GetPort(&savePort);
  3288. X    whichWindow = (WindowPtr)myEvent->message;
  3289. X    SetPort(whichWindow);
  3290. X    BeginUpdate(whichWindow);
  3291. X    EraseRect(&whichWindow->portRect);
  3292. X    if (whichWindow == cwindow) {
  3293. X    DrawGrowIcon(whichWindow);
  3294. X    RedrawScreen();
  3295. X    }
  3296. X    EndUpdate(whichWindow);
  3297. X    SetPort(savePort);
  3298. X}
  3299. X
  3300. XDoCommand(choice)
  3301. X  long choice;
  3302. X{
  3303. X    int theMenu,theItem;
  3304. X    
  3305. X    /* decode the menu choice */
  3306. X    theMenu = HiWord(choice);
  3307. X    theItem = LoWord(choice);
  3308. X    
  3309. X    CursorOff();
  3310. X    HiliteMenu(theMenu);
  3311. X    switch (theMenu) {
  3312. X    case appleID:
  3313. X    DoAppleMenu(theItem);
  3314. X    break;
  3315. X    case fileID:
  3316. X    DoFileMenu(theItem);
  3317. X    break;
  3318. X    case editID:
  3319. X    DoEditMenu(theItem);
  3320. X    break;
  3321. X    case controlID:
  3322. X    DoControlMenu(theItem);
  3323. X    break;
  3324. X    }
  3325. X    HiliteMenu(0);
  3326. X    CursorOn();
  3327. X}
  3328. X
  3329. Xpascal aboutfilter(theDialog,theEvent,itemHit)
  3330. X  DialogPtr theDialog; EventRecord *theEvent; int *itemHit;
  3331. X{
  3332. X    return (theEvent->what == mouseDown ? -1 : 0);
  3333. X}
  3334. X
  3335. XDoAppleMenu(theItem)
  3336. X  int theItem;
  3337. X{
  3338. X    DialogRecord mydialog;
  3339. X    char name[256];
  3340. X    GrafPtr gp;
  3341. X    int n;
  3342. X
  3343. X    switch (theItem) {
  3344. X    case 1:
  3345. X    GetNewDialog(129,&mydialog,-1L);
  3346. X    ModalDialog(aboutfilter,&n);
  3347. X    CloseDialog(&mydialog);
  3348. X    break;
  3349. X    default:
  3350. X    GetItem(appleMenu,theItem,name);
  3351. X    GetPort(&gp);
  3352. X    OpenDeskAcc(name);
  3353. X    SetPort(gp);
  3354. X    break;
  3355. X    }
  3356. X}
  3357. X
  3358. Xpascal int filefilter(pblock)
  3359. X  ParmBlkPtr pblock;
  3360. X{
  3361. X    unsigned char *p; int len;
  3362. X    p = pblock->fileParam.ioNamePtr; len = *p++ &0xFF;
  3363. X    return (len >= 4 && strncmp(p+len-4,".lsp",4) == 0 ? 0 : -1);
  3364. X}
  3365. X
  3366. XDoFileMenu(theItem)
  3367. X  int theItem;
  3368. X{
  3369. X    SFReply loadfile;
  3370. X    Point p;
  3371. X
  3372. X    switch (theItem) {
  3373. X    case 1:    /* load */
  3374. X    case 2:    /* load noisily */
  3375. X    p.h = 100; p.v = 100;
  3376. X    SFGetFile(p,"\P",filefilter,-1,filetypes,0L,&loadfile);
  3377. X    if (loadfile.good) {
  3378. X        HiliteMenu(0);
  3379. X        SetVol(0L,loadfile.vRefNum);
  3380. X        if (xlload(PtoCstr(loadfile.fName),1,(theItem == 1 ? 0 : 1)))
  3381. X        scrflush();
  3382. X        else
  3383. X        xlabort("load error");
  3384. X    }
  3385. X    break;
  3386. X    case 4:    /* quit */
  3387. X    wrapup();
  3388. X    }
  3389. X}
  3390. X
  3391. XDoEditMenu(theItem)
  3392. X  int theItem;
  3393. X{
  3394. X    switch (theItem) {
  3395. X    case 1:    /* undo */
  3396. X    case 3:    /* cut */
  3397. X    case 4:    /* copy */
  3398. X    case 5:    /* paste */
  3399. X    case 6:    /* clear */
  3400. X    SystemEdit(theItem-1);
  3401. X    break;
  3402. X    }
  3403. X}
  3404. X
  3405. XDoControlMenu(theItem)
  3406. X  int theItem;
  3407. X{
  3408. X    scrflush();
  3409. X    HiliteMenu(0);
  3410. X    switch (theItem) {
  3411. X    case 1:    /* break */
  3412. X    xlbreak("user break",s_unbound);
  3413. X    break;
  3414. X    case 2:    /* continue */
  3415. X    xlcontinue();
  3416. X    break;
  3417. X    case 3:    /* clean-up error */
  3418. X    xlcleanup();
  3419. X    break;
  3420. X    case 4:    /* Cancel input */
  3421. X    xlabort("input canceled");
  3422. X    break;
  3423. X    case 5:    /* Top Level */
  3424. X    xltoplevel();
  3425. X    break;
  3426. X    case 7:    /* split screen */
  3427. X    scrsplit(splitmode ? FALSE : TRUE);
  3428. X    break;
  3429. X    }
  3430. X}
  3431. X
  3432. Xscrsplit(split)
  3433. X  int split;
  3434. X{
  3435. X    ShowHide(cwindow,0);
  3436. X    if (split) {
  3437. X    CheckItem(controlMenu,7,-1);
  3438. X    ShowHide(gwindow,-1);
  3439. X    MoveWindow(cwindow,sHorizontal,sVertical,-1);
  3440. X    SizeWindow(cwindow,sWidth,sHeight,-1);
  3441. X    InvalRect(&cwindow->portRect);
  3442. X    SetupScreen();
  3443. X    }
  3444. X    else {
  3445. X    CheckItem(controlMenu,7,0);
  3446. X    ShowHide(gwindow,0);
  3447. X    MoveWindow(cwindow,nHorizontal,nVertical,-1);
  3448. X    SizeWindow(cwindow,nWidth,nHeight,-1);
  3449. X    InvalRect(&cwindow->portRect);
  3450. X    SetupScreen();
  3451. X    }
  3452. X    ShowHide(cwindow,-1);
  3453. X    splitmode = split;
  3454. X}
  3455. X
  3456. XSetupScreen()
  3457. X{
  3458. X    FontInfo info;
  3459. X    Rect *pRect;
  3460. X
  3461. X    /* get font information */
  3462. X    GetFontInfo(&info);
  3463. X
  3464. X    /* compute the top and bottom margins */
  3465. X    tmargin = TextMargin + info.ascent;
  3466. X    lmargin = TextMargin;
  3467. X
  3468. X    /* compute the x and y increments */
  3469. X    xinc = info.widMax;
  3470. X    yinc = info.ascent + info.descent + info.leading;
  3471. X
  3472. X    /* compute the character dimensions of the screen */
  3473. X    pRect = &cwindow->portRect;
  3474. X    scrh = (pRect->bottom - (2 * TextMargin) - (SBarWidth - 1)) / yinc;
  3475. X    if (scrh > SCRH) scrh = SCRH;
  3476. X    scrw = (pRect->right - (2 * TextMargin) - (SBarWidth - 1)) / xinc;
  3477. X    if (scrw > SCRW) scrw = SCRW;
  3478. X    
  3479. X    /* clear the screen */
  3480. X    scrclear();
  3481. X}
  3482. X
  3483. XCursorUpdate()
  3484. X{
  3485. X    if (cursorstate != -1)
  3486. X    if (cursortime < TickCount()) {
  3487. X        scrposition(x,y);
  3488. X        if (cursorstate) {
  3489. X        DrawChar(' ');
  3490. X        cursortime = TickCount() + TIMEOFF;
  3491. X        cursorstate = 0;
  3492. X        }
  3493. X        else {
  3494. X        DrawChar('_');
  3495. X        cursortime = TickCount() + TIMEON;
  3496. X        cursorstate = 1;
  3497. X        }
  3498. X    }
  3499. X}
  3500. X
  3501. XCursorOn()
  3502. X{
  3503. X    cursortime = TickCount();
  3504. X    cursorstate = 0;
  3505. X}
  3506. X
  3507. XCursorOff()
  3508. X{
  3509. X    if (cursorstate == 1) {
  3510. X    scrposition(x,y);
  3511. X    DrawChar(' ');
  3512. X    }
  3513. X    cursorstate = -1;
  3514. X}
  3515. X
  3516. XRedrawScreen()
  3517. X{
  3518. X    char *Line; int y;
  3519. X    Line = topline;
  3520. X    for (y = 0; y < scrh; y++) {
  3521. X    scrposition(0,y);
  3522. X    DrawText(Line,0,scrw);
  3523. X    nextline(&Line);
  3524. X    }
  3525. X}
  3526. X
  3527. Xnextline(pline)
  3528. X  char **pline;
  3529. X{
  3530. X    if ((*pline += SCRW) >= &screen[SCRH*SCRW])
  3531. X    *pline = screen;
  3532. X}
  3533. X
  3534. Xscrollup()
  3535. X{
  3536. X    RgnHandle updateRgn;
  3537. X    Rect rect;
  3538. X    int x;
  3539. X    updateRgn = NewRgn();
  3540. X    rect = cwindow->portRect;
  3541. X    rect.bottom -= SBarWidth - 1;
  3542. X    rect.right -= SBarWidth - 1;
  3543. X    ScrollRect(&rect,0,-yinc,updateRgn);
  3544. X    DisposeRgn(updateRgn);
  3545. X    for (x = 0; x < SCRW; x++)
  3546. X    topline[x] = ' ';
  3547. X    nextline(&topline);
  3548. X}
  3549. X
  3550. X======================== macstuff.c ==========================================
  3551. X
  3552. X/* macstuff.c - macintosh interface routines for xlisp */
  3553. X
  3554. X#include <stdio.h>
  3555. X
  3556. X/* program limits */
  3557. X#define LINEMAX     200    /* maximum line length */
  3558. X
  3559. X/* externals */
  3560. Xextern FILE *tfp;
  3561. Xextern int x;
  3562. X
  3563. X/* local variables */
  3564. Xstatic char linebuf[LINEMAX+1],*lineptr;
  3565. Xstatic int linepos[LINEMAX],linelen;
  3566. Xstatic long rseed = 1L;
  3567. X
  3568. Xosinit(name)
  3569. X  char *name;
  3570. X{
  3571. X    /* initialize the mac interface routines */
  3572. X    macinit();
  3573. X
  3574. X    /* initialize the line editor */
  3575. X    linelen = 0;
  3576. X}
  3577. X
  3578. Xosfinish()
  3579. X{
  3580. X}
  3581. X
  3582. Xoserror(msg)
  3583. X{
  3584. X    char line[100],*p;
  3585. X    sprintf(line,"error: %s\n",msg);
  3586. X    for (p = line; *p != '\0'; ++p)
  3587. X    ostputc(*p);
  3588. X}
  3589. X
  3590. Xint osrand(n)
  3591. X  int n;
  3592. X{
  3593. X    long k1;
  3594. X    
  3595. X    /* make sure we don't get stuck at zero */
  3596. X    if (rseed == 0L) rseed = 1L;
  3597. X    
  3598. X    /* algorithm taken from Dr. Dobbs Journal, November 1985, Page 91 */
  3599. X    k1 = rseed / 127773L;
  3600. X    if ((rseed = 16807L * (rseed - k1 * 127773L) - k1 * 2836L) < 0L)
  3601. X    rseed += 2147483647L;
  3602. X    
  3603. X    /* return a random number between 0 and n-1 */
  3604. X    return ((int)(rseed % (long)n));
  3605. X}
  3606. X
  3607. XFILE *osaopen(name,mode)
  3608. X  char *name,*mode;
  3609. X{
  3610. X    return (fopen(name,mode));
  3611. X}
  3612. X
  3613. XFILE *osbopen(name,mode)
  3614. X  char *name,*mode;
  3615. X{
  3616. X    char nmode[4];
  3617. X    strcpy(nmode,mode); strcat(nmode,"b");
  3618. X    return (fopen(name,nmode));
  3619. X}
  3620. X
  3621. Xint osclose(fp)
  3622. X  FILE *fp;
  3623. X{
  3624. X    return (fclose(fp));
  3625. X}
  3626. X
  3627. Xint osagetc(fp)
  3628. X  FILE *fp;
  3629. X{
  3630. X    return (getc(fp));
  3631. X}
  3632. X
  3633. Xint osbgetc(fp)
  3634. X  FILE *fp;
  3635. X{
  3636. X    return (getc(fp));
  3637. X}
  3638. X
  3639. Xint osaputc(ch,fp)
  3640. X  int ch; FILE *fp;
  3641. X{
  3642. X    return (putc(ch,fp));
  3643. X}
  3644. X
  3645. Xint osbputc(ch,fp)
  3646. X  int ch; FILE *fp;
  3647. X{
  3648. X    return (putc(ch,fp));
  3649. X}
  3650. X
  3651. Xint ostgetc()
  3652. X{
  3653. X    int ch,i;
  3654. X
  3655. X    if (linelen--) return (*lineptr++);
  3656. X    linelen = 0;
  3657. X    while ((ch = scrgetc()) != '\r')
  3658. X    switch (ch) {
  3659. X    case EOF:
  3660. X        return (ostgetc());
  3661. X    case '\010':
  3662. X        if (linelen > 0) {
  3663. X        linelen--;
  3664. X        while (x > linepos[linelen])
  3665. X            scrdelete();
  3666. X        }
  3667. X        break;
  3668. X    default:
  3669. X        if (linelen < LINEMAX) {
  3670. X            linebuf[linelen] = ch;
  3671. X        linepos[linelen] = x;
  3672. X        linelen++;
  3673. X        }
  3674. X        scrputc(ch);
  3675. X        break;
  3676. X    }
  3677. X    linebuf[linelen++] = '\n';
  3678. X    scrputc('\r'); scrputc('\n');
  3679. X    if (tfp)
  3680. X    for (i = 0; i < linelen; ++i)
  3681. X        osaputc(linebuf[i],tfp);
  3682. X    lineptr = linebuf; linelen--;
  3683. X    return (*lineptr++);
  3684. X}
  3685. X
  3686. Xint ostputc(ch)
  3687. X  int ch;
  3688. X{
  3689. X    if (ch == '\n')
  3690. X    scrputc('\r');
  3691. X    scrputc(ch);
  3692. X    if (tfp)
  3693. X    osaputc(ch,tfp);
  3694. X    return (1);
  3695. X}
  3696. X
  3697. Xosflush()
  3698. X{
  3699. X    lineptr = linebuf;
  3700. X    linelen = 0;
  3701. X}
  3702. X
  3703. Xoscheck()
  3704. X{
  3705. X    DoEvent();
  3706. X}
  3707. X
  3708. X
  3709. X=========================== osdefs.h =====================================
  3710. X
  3711. Xextern LVAL xptsize(),
  3712. X        xhidepen(),xshowpen(),xgetpen(),xpensize(),xpenmode(),
  3713. X            xpenpat(),xpennormal(),xmoveto(),xmove(),xlineto(),xline(),
  3714. X        xshowgraphics(),xhidegraphics(),xcleargraphics(),
  3715. X        xtool(),xtool16(),xtool32(),xnewhandle(),xnewptr(),
  3716. X        xhiword(),xloword(),xrdnohang();
  3717. X
  3718. X=========================== osptrs.h =====================================
  3719. X
  3720. X{    "HIDEPEN",            S, xhidepen        }, /* 300 */
  3721. X{    "SHOWPEN",            S, xshowpen        }, /* 301 */
  3722. X{    "GETPEN",            S, xgetpen        }, /* 302 */
  3723. X{    "PENSIZE",            S, xpensize        }, /* 303 */
  3724. X{    "PENMODE",            S, xpenmode        }, /* 304 */
  3725. X{    "PENPAT",            S, xpenpat        }, /* 305 */
  3726. X{    "PENNORMAL",            S, xpennormal        }, /* 306 */
  3727. X{    "MOVETO",            S, xmoveto        }, /* 307 */
  3728. X{    "MOVE",                S, xmove        }, /* 308 */
  3729. X{    "LINETO",            S, xlineto        }, /* 309 */
  3730. X{    "LINE",                S, xline        }, /* 310 */
  3731. X{    "SHOW-GRAPHICS",        S, xshowgraphics    }, /* 311 */
  3732. X{    "HIDE-GRAPHICS",        S, xhidegraphics    }, /* 312 */
  3733. X{    "CLEAR-GRAPHICS",        S, xcleargraphics    }, /* 313 */
  3734. X{    "TOOLBOX",            S, xtool        }, /* 314 */
  3735. X{    "TOOLBOX-16",            S, xtool16        }, /* 315 */
  3736. X{    "TOOLBOX-32",            S, xtool32        }, /* 316 */
  3737. X{    "NEWHANDLE",            S, xnewhandle        }, /* 317 */
  3738. X{    "NEWPTR",            S, xnewptr        }, /* 318 */
  3739. X{    "HIWORD",            S, xhiword        }, /* 319 */
  3740. X{    "LOWORD",            S, xloword        }, /* 320 */
  3741. X{    "READ-CHAR-NO-HANG",        S, xrdnohang        }, /* 321 */
  3742. X{    "COMMAND-POINT-SIZE",        S, xptsize        }, /* 322 */
  3743. X
  3744. X
  3745. X======================== Xlisp.Rsrc ==========================================
  3746. X
  3747. XXLisp.Rsrc
  3748. X
  3749. XTYPE WIND
  3750. X  ,128
  3751. XXLISP version 2.0
  3752. X41 4 339 508
  3753. XInVisible GoAway
  3754. X0
  3755. X0
  3756. X
  3757. XTYPE WIND
  3758. X  ,129
  3759. XGraphics Window
  3760. X22 4 254 508
  3761. XInVisible NoGoAway
  3762. X2
  3763. X0
  3764. X
  3765. XTYPE DLOG
  3766. X  ,129
  3767. XAbout XLISP
  3768. X50 100 290 395
  3769. XVisible NoGoAway
  3770. X3
  3771. X0
  3772. X129
  3773. X
  3774. XTYPE DITL
  3775. X  ,129
  3776. X9
  3777. X
  3778. XstaticText
  3779. X20 20 40 275
  3780. XXLISP v2.0, February 6, 1988
  3781. X
  3782. XstaticText
  3783. X40 20 60 275
  3784. XCopyright (c) 1988, by David Betz
  3785. X
  3786. XstaticText
  3787. X60 20 80 275
  3788. XAll Rights Reserved
  3789. X
  3790. XstaticText
  3791. X90 20 110 275
  3792. XAuthor contact information:
  3793. X
  3794. XstaticText
  3795. X110 40 130 275
  3796. XDavid Betz
  3797. X
  3798. XstaticText
  3799. X130 40 150 275
  3800. X127 Taylor Road
  3801. X
  3802. XstaticText
  3803. X150 40 170 275
  3804. XPeterborough, NH  03458
  3805. X
  3806. XstaticText
  3807. X170 40 190 275
  3808. X(603) 924-6936
  3809. X
  3810. XstaticText
  3811. X200 20 220 275
  3812. XPortions Copyright Think Technologies
  3813. X
  3814. XTYPE MENU
  3815. X  ,1
  3816. X\14
  3817. XAbout XLISP
  3818. X(-
  3819. X
  3820. XTYPE MENU
  3821. X  ,256
  3822. XFile
  3823. XLoad.../L
  3824. XLoad Noisily.../N
  3825. X(-
  3826. XQuit/Q
  3827. X
  3828. XTYPE MENU
  3829. X  ,257
  3830. XEdit
  3831. XUndo/Z
  3832. X(-
  3833. XCut/X
  3834. XCopy/C
  3835. XPaste/V
  3836. XClear
  3837. X
  3838. XTYPE MENU
  3839. X  ,258
  3840. XControl
  3841. XBreak/B
  3842. XContinue/P
  3843. XClean Up Error/G
  3844. XCancel Input/U
  3845. XTop Level/T
  3846. X(-
  3847. XSplit Screen/S
  3848. X
  3849. X
  3850. X======================== Alles ist gemacht  ==================================
  3851. X
  3852. X
  3853. X-- 
  3854. XEric F. Johnson, Boulware Technologies, Inc. 
  3855. X415 W. Travelers Trail, Burnsville, MN 55337 USA.  Phone: +1 612-894-0313. 
  3856. Xerc@pai.mn.org    - or -   bungia!pai!erc
  3857. X(We have a very dumb mailer, so please send a bang-!-style return address.)
  3858. X
  3859. X
  3860. SHAR_EOF
  3861. if test 27375 -ne "`wc -c 'xlisp.mac'`"
  3862. then
  3863.     echo shar: error transmitting "'xlisp.mac'" '(should have been 27375 characters)'
  3864. fi
  3865. #    End of shell archive
  3866. exit 0
  3867. -- 
  3868. Gary Murphy                   uunet!mitel!sce!cognos!garym
  3869.                               (garym%cognos.uucp@uunet.uu.net)
  3870. (613) 738-1338 x5537          Cognos Inc. P.O. Box 9707 Ottawa K1G 3N3
  3871. "There are many things which do not concern the process" - Joan of Arc
  3872.  
  3873.